From 7700671b1d8f4d0ce4d1ad28b7c828cfeff9a80a Mon Sep 17 00:00:00 2001 From: xevidos Date: Thu, 24 Oct 2019 17:56:23 -0400 Subject: [PATCH] Updated search functions for workspace replacement, Added callback to modal, Updated selection text for find and replace --- components/active/init.js | 14 ++++-- components/editor/dialog.php | 25 ---------- components/editor/init.js | 32 +++++++++--- components/filemanager/class.filemanager.php | 4 +- js/modal.js | 51 +++++++++++--------- 5 files changed, 66 insertions(+), 60 deletions(-) diff --git a/components/active/init.js b/components/active/init.js index 752cfc4..357b1dd 100755 --- a/components/active/init.js +++ b/components/active/init.js @@ -752,14 +752,18 @@ ////////////////////////////////////////////////////////////////// getSelectedText: function() { - var path = this.getPath(); - var session = this.sessions[path]; + + let path = this.getPath(); + let session = this.sessions[path]; if( path && this.isOpen( path ) ) { - return session.getTextRange( - codiad.editor.getActive() - .getSelectionRange() ); + + console.log( "Session:", session ); + console.log( "selection: ", codiad.editor.getActive().getSelectionRange() ) + console.log( "text: ", session.getTextRange( codiad.editor.getActive().getSelectionRange() ) ) + return session.getTextRange( codiad.editor.getActive().getSelectionRange() ); } else { + codiad.message.error( i18n( 'No Open Files or Selected Text' ) ); } }, diff --git a/components/editor/dialog.php b/components/editor/dialog.php index 7aeeede..c64e597 100755 --- a/components/editor/dialog.php +++ b/components/editor/dialog.php @@ -86,28 +86,3 @@ checkSession(); } ?> - diff --git a/components/editor/init.js b/components/editor/init.js index 589dfd6..063409e 100755 --- a/components/editor/init.js +++ b/components/editor/init.js @@ -1359,13 +1359,33 @@ ////////////////////////////////////////////////////////////////// openSearch: function( type ) { + if( this.getActive() ) { - codiad.modal.load( 400, - 'components/editor/dialog.php?action=search&type=' + - type ); - codiad.modal.hideOverlay(); - } else { - codiad.message.error( 'No Open Files' ); + + let selected = codiad.active.getSelectedText(); + + codiad.modal.load( + 400, + 'components/editor/dialog.php?action=search&type=' + type, + {}, + function( c ) { + + let input = c.find( 'input:first' ); + let textarea = c.find( 'textarea:first' ); + + if( input.css( 'display' ) !== 'none' ) { + + input.val( selected ) + input.focus(); + } else if( textarea.css( 'display' ) !== 'none' ) { + + textarea.val( selected ) + textarea.focus(); + } + console.log( input, textarea ); + codiad.modal.hideOverlay(); + } + ); } }, diff --git a/components/filemanager/class.filemanager.php b/components/filemanager/class.filemanager.php index 450ffcb..f103633 100755 --- a/components/filemanager/class.filemanager.php +++ b/components/filemanager/class.filemanager.php @@ -649,7 +649,7 @@ class Filemanager extends Common { $return = array(); $input = str_replace( '"', '', $query ); - $cmd = 'find -L ' . escapeshellarg( $path ) . ' -iregex '.escapeshellarg( '.*' . $options["filetype"] ) . ' -type f -print0 | xargs -0 grep -i -I -n -R -H ' . escapeshellarg( $input ) . ''; + $cmd = 'find -L ' . escapeshellarg( $path ) . ' -iregex ' . escapeshellarg( '.*' . $options["filetype"] ) . ' -type f -print0 | xargs -0 grep -i -I -n -R -H ' . escapeshellarg( $input ) . ''; $output = shell_exec( $cmd ); $output_arr = explode( "\n", $output ); foreach ( $output_arr as $line ) { @@ -660,7 +660,7 @@ class Filemanager extends Common { $da['line'] = $data[1]; $da['file'] = str_replace( $path, '', $data[0] ); - $da['result'] = $_SESSION["project"] . str_replace( $path, '', $data[0] ); + $da['result'] = str_replace( WORKSPACE . '/', '', $data[0] ); $da['string'] = str_replace( $data[0] . ":" . $data[1] . ':', '', $line ); $return[] = $da; } diff --git a/js/modal.js b/js/modal.js index 6147d08..141b67d 100755 --- a/js/modal.js +++ b/js/modal.js @@ -19,35 +19,42 @@ .hide(); }, - load: function( width, url, data ) { + load: function( width, url, data, callback = null ) { data = data || {}; - var bounds = this._getBounds( width ); + let bounds = this._getBounds( width ); + let content = $( '#modal-content' ) $('#modal') - .css({ - 'top': bounds.top, - 'left': bounds.left, - 'min-width': width + 'px', - 'margin-left': '-' + Math.ceil( width / 2 ) + 'px' - }) - .draggable({ - handle: '#drag-handle' - }); - $('#modal-content') - .html(''); - this.load_process = $.get( url, data, function( data ) { - $('#modal-content').html( data ); - // Fix for Firefox autofocus goofiness - $('input[autofocus="autofocus"]') - .focus(); + .css({ + 'top': bounds.top, + 'left': bounds.left, + 'min-width': width + 'px', + 'margin-left': '-' + Math.ceil( width / 2 ) + 'px' + }) + .draggable({ + handle: '#drag-handle' }); - var event = {animationPerformed: false}; - amplify.publish( 'modal.onLoad', event ); + content.html(''); + + this.load_process = $.get( url, data, function( data ) { + + content.html( data ); + // Fix for Firefox autofocus goofiness + $('#modal-content input[autofocus="autofocus"]').focus(); + + if( callback ) { + + callback( content ); + } + }); + + let event = {animationPerformed: false}; + amplify.publish( 'modal.onLoad', event ); + // If no plugin has provided a custom load animation if( ! event.animationPerformed ) { - $('#modal, #modal-overlay') - .fadeIn(200); + $('#modal, #modal-overlay').fadeIn(200); } codiad.sidebars.modalLock = true; },