Вход Регистрация
Файл: upload/admin/view/javascript/ckeditor/plugins/codemirror/js/util/search.js
Строк: 164
<?php
// Define search commands. Depends on dialog.js or another
// implementation of the openDialog method.

// Replace works a little oddly -- it will do the replace on the next
// Ctrl-G (or whatever is bound to findNext) press. You prevent a
// replace by making sure the match is no longer selected when hitting
// Ctrl-G.

(function() {
  function 
SearchState() {
    
this.posFrom this.posTo this.query null;
    
this.marked = [];
  }
  function 
getSearchState(cm) {
    return 
cm._searchState || (cm._searchState = new SearchState());
  }
  function 
getSearchCursor(cmquerypos) {
    
// Heuristic: if the query string is all lowercase, do a case insensitive search.
    
return cm.getSearchCursor(querypostypeof query == "string" && query == query.toLowerCase());
  }
  function 
dialog(cmtextshortTextf) {
    if (
cm.openDialogcm.openDialog(textf);
    else 
f(prompt(shortText""));
  }
  function 
confirmDialog(cmtextshortTextfs) {
    if (
cm.openConfirmcm.openConfirm(textfs);
    else if (
confirm(shortText)) fs[0]();
  }
  function 
parseQuery(query) {
    var 
isRE query.match(/^/(.*)/([a-z]*)$/);
    return 
isRE ? new RegExp(isRE[1], isRE[2].indexOf("i") == -"" "i") : query;
  }
  var 
queryDialog =
    
'Search: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
  function 
doSearch(cmrev) {
    var 
state getSearchState(cm);
    if (
state.query) return findNext(cmrev);
    
dialog(cmqueryDialog"Search for:", function(query) {
      
cm.operation(function() {
        if (!
query || state.query) return;
        
state.query parseQuery(query);
        if (
cm.lineCount() < 2000) { // This is too expensive on big documents.
          
for (var cursor getSearchCursor(cmstate.query); cursor.findNext();)
            
state.marked.push(cm.markText(cursor.from(), cursor.to(),
                                          {
className"CodeMirror-searching"}));
        }
        
state.posFrom state.posTo cm.getCursor();
        
findNext(cmrev);
      });
    });
  }
  function 
findNext(cmrev) {cm.operation(function() {
    var 
state getSearchState(cm);
    var 
cursor getSearchCursor(cmstate.queryrev state.posFrom state.posTo);
    if (!
cursor.find(rev)) {
      
cursor getSearchCursor(cmstate.queryrev ? {linecm.lineCount() - 1} : {line0ch0});
      if (!
cursor.find(rev)) return;
    }
    
cm.setSelection(cursor.from(), cursor.to());
    
state.posFrom cursor.from(); state.posTo cursor.to();
  });}
  function 
clearSearch(cm) {cm.operation(function() {
    var 
state getSearchState(cm);
    if (!
state.query) return;
    
state.query null;
    for (var 
0state.marked.length; ++istate.marked[i].clear();
    
state.marked.length 0;
  });}

  var 
replaceQueryDialog =
    
'Replace: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
  var 
replacementQueryDialog 'With: <input type="text" style="width: 10em"/>';
  var 
doReplaceConfirm "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
  function 
replace(cmall) {
    
dialog(cmreplaceQueryDialog"Replace:", function(query) {
      if (!
query) return;
      
query parseQuery(query);
      
dialog(cmreplacementQueryDialog"Replace with:", function(text) {
        if (
all) {
          
cm.operation(function() {
            for (var 
cursor getSearchCursor(cmquery); cursor.findNext();) {
              if (
typeof query != "string") {
                var 
match cm.getRange(cursor.from(), cursor.to()).match(query);
                
cursor.replace(text.replace(/$(d)/, function(_i) {return match[i];}));
              } else 
cursor.replace(text);
            }
          });
        } else {
          
clearSearch(cm);
          var 
cursor getSearchCursor(cmquerycm.getCursor());
          function 
advance() {
            var 
start cursor.from(), match;
            if (!(
match cursor.findNext())) {
              
cursor getSearchCursor(cmquery);
              if (!(
match cursor.findNext()) ||
                  (
start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
            }
            
cm.setSelection(cursor.from(), cursor.to());
            
confirmDialog(cmdoReplaceConfirm"Replace?",
                          [function() {
doReplace(match);}, advance]);
          }
          function 
doReplace(match) {
            
cursor.replace(typeof query == "string" text :
                           
text.replace(/$(d)/, function(_i) {return match[i];}));
            
advance();
          }
          
advance();
        }
      });
    });
  }

  
CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
  
CodeMirror.commands.findNext doSearch;
  
CodeMirror.commands.findPrev = function(cm) {doSearch(cmtrue);};
  
CodeMirror.commands.clearSearch clearSearch;
  
CodeMirror.commands.replace replace;
  
CodeMirror.commands.replaceAll = function(cm) {replace(cmtrue);};
})();
?>
Онлайн: 0
Реклама