Skip to content

Commit

Permalink
merged with master
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Daniels committed Apr 8, 2012
2 parents 239f2eb + 0736c06 commit ba93f29
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 44 deletions.
20 changes: 13 additions & 7 deletions client/ext/quicksearch/quicksearch.js
Expand Up @@ -74,7 +74,12 @@ module.exports = ext.register("ext/quicksearch/quicksearch", {

init : function(amlNode){
var _self = this;

var ace;

txtQuickSearch.addEventListener("clear", function(e) {
_self.execSearch(false, false, true);
})

txtQuickSearch.addEventListener("keydown", function(e) {
switch (e.keyCode){
case 13: //ENTER
Expand Down Expand Up @@ -122,6 +127,7 @@ module.exports = ext.register("ext/quicksearch/quicksearch", {
});

txtQuickSearch.addEventListener("keyup", function(e) {
ace = _self.$getAce();
switch (e.keyCode) {
case 8: // BACKSPACE
var ace = _self.$getAce();
Expand Down Expand Up @@ -214,7 +220,7 @@ module.exports = ext.register("ext/quicksearch/quicksearch", {
});

var ranges = ace.$search.findAll(ace.getSession());
if (!ranges || !ranges.length) {
if (!ranges || !ranges.length || !txtQuickSearch.getValue()) {
oIter.innerHTML = "0";
oTotal.innerHTML = "of 0";
return;
Expand All @@ -225,15 +231,14 @@ module.exports = ext.register("ext/quicksearch/quicksearch", {
if (newCount < 1) {
newCount = String(ranges.length);
}

oIter.innerHTML = String(newCount);
}
else {
var crtIdx = -1;
var cur = this.currentRange;
if (cur) {
// sort ranges by position in the current document
ranges.sort(cur.compareRange.bind(cur));
//ranges.sort(cur.compareRange.bind(cur));
var range;
var start = cur.start;
var end = cur.end;
Expand Down Expand Up @@ -338,12 +343,13 @@ module.exports = ext.register("ext/quicksearch/quicksearch", {
return;

var searchTxt = txtQuickSearch.getValue();
if (!searchTxt)
return;

if (searchTxt.length == 1 && ace.getSession().getDocument().getLength() > MAX_LINES_SOFT)
if (searchTxt.length < 2 && ace.getSession().getDocument().getLength() > MAX_LINES_SOFT)
return;

//if (!searchTxt)
// return this.updateCounter();

var options = {
backwards: !!backwards,
wrap: true,
Expand Down
33 changes: 33 additions & 0 deletions client/ext/searchreplace/searchreplace.css
@@ -0,0 +1,33 @@
#divSearchReplaceCount {
position: absolute;
width: auto;
height: 19px;
right: 12px;
top: 18px;
}

#divSearchReplaceCount .searchIter,
#divSearchReplaceCount .searchTotal {
color: #aaa;
font-size: 11px;
height: 19px;
line-height: 20px;
text-align: center;
vertical-align: middle;
display:inline;
float: left;
}

#divSearchReplaceCount .searchIter {
margin: 0 1px 0 0;
padding: 0 0 0 7px;
}

#divSearchReplaceCount .searchTotal {
margin: 0;
padding: 0 5px 0 2px;
}

.tb_textbox.searchTxt .sbtb_middle input {
width: 255px;
}
74 changes: 74 additions & 0 deletions client/ext/searchreplace/searchreplace.js
Expand Up @@ -13,20 +13,26 @@ var util = require("core/util");
var code = require("ext/code/code");
var search = require("ace/search");
var editors = require("ext/editors/editors");
var css = require("text!ext/searchreplace/searchreplace.css");
var markup = require("text!ext/searchreplace/searchreplace.xml");

var oIter, oTotal;

module.exports = ext.register("ext/searchreplace/searchreplace", {
name : "Searchreplace",
dev : "Ajax.org",
type : ext.GENERAL,
alone : true,
css : css,
markup : markup,
commands : {
"search": {hint: "search for a string inside the active document"},
"searchreplace": {hint: "search for a string inside the active document and replace it"}
},
hotitems: {},

currentRange: null,

nodes : [],

hook : function(){
Expand Down Expand Up @@ -62,6 +68,7 @@ module.exports = ext.register("ext/searchreplace/searchreplace", {

init : function(amlNode){
var _self = this;
apf.importCssString(_self.css);

this.txtFind = txtFind;//winSearchReplace.selectSingleNode("a:vbox/a:hbox[1]/a:textbox[1]");
this.txtReplace = txtReplace;//winSearchReplace.selectSingleNode("a:vbox/a:hbox[1]/a:textbox[1]");
Expand Down Expand Up @@ -162,6 +169,7 @@ module.exports = ext.register("ext/searchreplace/searchreplace", {
? "Search & Replace" : "Search");
winSearchReplace.show();
}
this.updateCounter();
}
else
winSearchReplace.hide();
Expand Down Expand Up @@ -234,11 +242,14 @@ module.exports = ext.register("ext/searchreplace/searchreplace", {
// regExp: false
// }
this.$editor.find(txt, options);
this.currentRange = this.$editor.selection.getRange();
}
else {
this.$editor.find(txt, options);
this.currentRange = this.$editor.selection.getRange();
}
chkSearchSelection.setAttribute("checked", false);
this.updateCounter();
},

replace: function() {
Expand Down Expand Up @@ -273,9 +284,72 @@ module.exports = ext.register("ext/searchreplace/searchreplace", {

this.$editor.gotoLine(line); // replaceAll jumps you elsewhere; go back to where you were

this.updateCounter();
ide.dispatchEvent("track_action", {type: "replace"});
},

updateCounter: function() {
var ace = this.$getAce();
var width, buttonWidth;

if (!oIter) {
oIter = document.getElementById("spanSearchReplaceIter");
oTotal = document.getElementById("spanSearchReplaceTotal");
}
/*
if (oIter.parentNode) {
if (!ace || !winQuickSearch.visible) {
oIter.parentNode.style.width = "0px";
return;
}
else
oIter.parentNode.style.width = "auto";
}
setTimeout(function() {
if (oIter.parentNode && txtQuickSearch && txtQuickSearch.$button) {
width = oIter.parentNode.offsetWidth || 0;
txtQuickSearch.$button.style.right = width + "px";
}
});
*/
var ranges = ace.$search.findAll(ace.getSession());
if (!ranges || !ranges.length) {
oIter.innerHTML = "0";
oTotal.innerHTML = "of 0";
return;
}
var crtIdx = -1;
var cur = this.currentRange;
if (cur) {
// sort ranges by position in the current document
//ranges.sort(cur.compareRange.bind(cur));
var range;
var start = cur.start;
var end = cur.end;
for (var i = 0, l = ranges.length; i < l; ++i) {
range = ranges[i];
if (range.isStart(start.row, start.column) && range.isEnd(end.row, end.column)) {
crtIdx = i;
break;
}
}
}


oIter.innerHTML = String(++crtIdx);
oTotal.innerHTML = "of " + ranges.length;
},

$getAce: function() {
var editor = editors.currentEditor;
if (!editor || !editor.ceEditor)
return;

var ceEditor = editor.ceEditor;
return ceEditor.$editor;
},

enable : function(){
this.nodes.each(function(item){
item.enable();
Expand Down
3 changes: 2 additions & 1 deletion client/ext/searchreplace/searchreplace.xml
Expand Up @@ -12,7 +12,8 @@
<a:vbox edge="15 10 20" padding="5">
<a:hbox align="center">
<a:label width="75">Search</a:label>
<a:textbox id="txtFind" flex="1" focusselect="true" />
<a:textbox id="txtFind" flex="1" focusselect="true" class="searchTxt"/>
<div id="divSearchReplaceCount"><span class="searchIter" id="spanSearchReplaceIter">0</span><span class="searchTotal" id="spanSearchReplaceTotal">0</span></div>
</a:hbox>
<a:hbox id="barSingleReplace" align="center">
<a:label width="75">Replace With</a:label>
Expand Down
59 changes: 24 additions & 35 deletions client/ext/vim/maps/util.js
Expand Up @@ -10,45 +10,34 @@ module.exports = {
currentMode: 'normal',
insertMode: function(editor) {
var _self = this;
var theme = editor && editor.getTheme() || "ace/theme/textmate";

ide.dispatchEvent("vim.changeMode", { mode : "insert" });

require(["require", theme], function (require) {
var isDarkTheme = require(theme).isDark;
_self.currentMode = 'insert';
// Switch editor to insert mode
editor.unsetStyle('insert-mode');

_self.currentMode = 'insert';
// Switch editor to insert mode
editor.unsetStyle('insert-mode');

var cursor = document.getElementsByClassName("ace_cursor")[0];
if (cursor) {
cursor.style.display = null;
cursor.style.backgroundColor = null;
cursor.style.opacity = null;
cursor.style.border = null;
cursor.style.borderLeftColor = isDarkTheme? "#eeeeee" : "#333333";
cursor.style.borderLeftStyle = "solid";
cursor.style.borderLeftWidth = "2px";
}
var cursor = document.getElementsByClassName("ace_cursor")[0];
if (cursor) {
cursor.removeAttribute("style"); // fall back to ace theme
}

editor.setOverwrite(false);
editor.keyBinding.$data.buffer = "";
editor.keyBinding.$data.state = "insertMode";
_self.onVisualMode = false;
_self.onVisualLineMode = false;
if(_self.onInsertReplaySequence) {
// Ok, we're apparently replaying ("."), so let's do it
editor.commands.macro = _self.onInsertReplaySequence;
editor.commands.replay(editor);
_self.onInsertReplaySequence = null;
_self.normalMode(editor);
} else {
// Record any movements, insertions in insert mode
if(!editor.commands.recording)
editor.commands.toggleRecording();
}
});
editor.setOverwrite(false);
editor.keyBinding.$data.buffer = "";
editor.keyBinding.$data.state = "insertMode";
_self.onVisualMode = false;
_self.onVisualLineMode = false;
if(_self.onInsertReplaySequence) {
// Ok, we're apparently replaying ("."), so let's do it
editor.commands.macro = _self.onInsertReplaySequence;
editor.commands.replay(editor);
_self.onInsertReplaySequence = null;
_self.normalMode(editor);
} else {
// Record any movements, insertions in insert mode
if(!editor.commands.recording)
editor.commands.toggleRecording();
}
},
normalMode: function(editor) {
// Switch editor to normal mode
Expand Down Expand Up @@ -119,4 +108,4 @@ module.exports = {
editor.moveCursorTo(pos.row, pos.column);
}
};
});
});
2 changes: 1 addition & 1 deletion support/jsdav
Submodule jsdav updated from 6adc96 to 8bc083

0 comments on commit ba93f29

Please sign in to comment.