diff --git a/apps/files_texteditor/js/editor.js b/apps/files_texteditor/js/editor.js index 081ecb75a8..cf6d8217c6 100644 --- a/apps/files_texteditor/js/editor.js +++ b/apps/files_texteditor/js/editor.js @@ -60,9 +60,9 @@ function showControls(filename,writeperms){ // Load the new toolbar. var savebtnhtml; if(writeperms=="true"){ - var editorcontrols = '
'; + var editorcontrols = '
'; } - var html = ''; + var html = '
'; $('#controls').append(html); $('#editorbar').fadeIn('slow'); var breadcrumbhtml = ''; @@ -74,6 +74,9 @@ function bindControlEvents(){ $("#editor_save").die('click',doFileSave).live('click',doFileSave); $('#editor_close').die('click',hideFileEditor).live('click',hideFileEditor); $('#gotolinebtn').die('click', goToLine).live('click', goToLine); + $('#editorsearchval').die('keyup', doSearch).live('keyup', doSearch); + $('#clearsearchbtn').die('click', resetSearch).live('click', resetSearch); + $('#nextsearchbtn').die('click', nextSearchResult).live('click', nextSearchResult); } // returns true or false if the editor is in view or not @@ -89,6 +92,48 @@ function goToLine(){ } +//resets the search +function resetSearch(){ + $('#editorsearchval').val(''); + $('#nextsearchbtn').remove(); + $('#clearsearchbtn').remove(); + window.aceEditor.gotoLine(0); +} + +// moves the cursor to the next search resukt +function nextSearchResult(){ + window.aceEditor.findNext(); +} +// Performs the initial search +function doSearch(){ + // check if search box empty? + if($('#editorsearchval').val()==''){ + // Hide clear button + window.aceEditor.gotoLine(0); + $('#nextsearchbtn').remove(); + $('#clearsearchbtn').remove(); + } else { + // New search + // Reset cursor + window.aceEditor.gotoLine(0); + // Do search + window.aceEditor.find($('#editorsearchval').val(),{ + backwards: false, + wrap: false, + caseSensitive: false, + wholeWord: false, + regExp: false + }); + // Show next and clear buttons + // check if already there + if($('#nextsearchbtn').length==0){ + var nextbtnhtml = ''; + var clearbtnhtml = ''; + $('#editorsearchval').after(nextbtnhtml).after(clearbtnhtml); + } + } +} + // Tries to save the file. function doFileSave(){ if(editorIsShown()){ @@ -168,22 +213,13 @@ function showFileEditor(dir,filename){ // Fades out the editor. function hideFileEditor(){ - // Fade out controls - $('#editor_close').fadeOut('slow'); - // Fade out the save button - $('#editor_save').fadeOut('slow'); - // Goto line items - $('#gotolinebtn').fadeOut('slow'); - $('#gotolineval').fadeOut('slow'); - // Fade out separators - $('.separator').fadeOut('slow'); - // Fade out breadcrumb - $('#breadcrumb_file').fadeOut('slow', function(){ $(this).remove();}); + // Fades out editor controls + $('#controls > :not(.actions,#file_access_panel),#breadcrumb_file').fadeOut('slow',function(){ + $(this).remove(); + }); // Fade out editor $('#editor').fadeOut('slow', function(){ - $('#editor_close').remove(); - $('#editor_save').remove(); - $('#editor').remove(); + $(this).remove(); var editorhtml = '
'; $('table').after(editorhtml); $('.actions,#file_access_panel').fadeIn('slow');