Added search by reference
Also added an option to search all files by default. Fixes #57 and #53.
This commit is contained in:
parent
72a682a309
commit
541ef85e2c
8 changed files with 90 additions and 62 deletions
|
@ -1,6 +1,6 @@
|
||||||
var mainWindow = null;
|
var mainWindow = null;
|
||||||
|
|
||||||
chrome.app.runtime.onLaunched.addListener(function(launchData) {
|
var openWindow = function(launchData) {
|
||||||
|
|
||||||
if (mainWindow) {
|
if (mainWindow) {
|
||||||
mainWindow.contentWindow.launchData = launchData;
|
mainWindow.contentWindow.launchData = launchData;
|
||||||
|
@ -37,4 +37,7 @@ chrome.app.runtime.onLaunched.addListener(function(launchData) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
};
|
||||||
|
|
||||||
|
chrome.app.runtime.onLaunched.addListener(openWindow);
|
||||||
|
chrome.app.runtime.onRestarted.addListener(openWindow);
|
|
@ -16,7 +16,7 @@
|
||||||
"^-d": { "ace": "selectMoreAfter" },
|
"^-d": { "ace": "selectMoreAfter" },
|
||||||
"^-p": { "command": "palette:open" },
|
"^-p": { "command": "palette:open" },
|
||||||
"^-P": { "command": "palette:open", "argument": "command" },
|
"^-P": { "command": "palette:open", "argument": "command" },
|
||||||
//"^-r": { "command": "palette:open", "argument": "reference" },
|
"^-r": { "command": "palette:open", "argument": "reference" },
|
||||||
"^-g": { "command": "palette:open", "argument": "line" },
|
"^-g": { "command": "palette:open", "argument": "line" },
|
||||||
"^-m": { "ace": "jumptomatching" },
|
"^-m": { "ace": "jumptomatching" },
|
||||||
"^-M": { "command": "sublime:expand-to-matching" },
|
"^-M": { "command": "sublime:expand-to-matching" },
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
{ "label": "Go To Anything", "command": "palette:open" },
|
{ "label": "Go To Anything", "command": "palette:open" },
|
||||||
{ "label": "Go To Line", "command": "palette:open", "argument": "line" },
|
{ "label": "Go To Line", "command": "palette:open", "argument": "line" },
|
||||||
{ "label": "Go To Search", "command": "palette:open", "argument": "search" },
|
{ "label": "Go To Search", "command": "palette:open", "argument": "search" },
|
||||||
|
{ "label": "Go To Reference", "command": "palette:open", "argument": "reference" },
|
||||||
{ "label": "Command Palette", "command": "palette:open", "argument": "command" },
|
{ "label": "Command Palette", "command": "palette:open", "argument": "command" },
|
||||||
"divider",
|
"divider",
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -39,6 +39,10 @@ make sure you don't have any syntax errors.
|
||||||
//We don't yet have a way to set the worker options, but you can disable it.
|
//We don't yet have a way to set the worker options, but you can disable it.
|
||||||
"useWorker": true,
|
"useWorker": true,
|
||||||
|
|
||||||
|
//By default, the palette searches the current file only unless you widen the scope.
|
||||||
|
//If you'd like it to search all open files by default, set this option to true.
|
||||||
|
"searchAllFiles": false,
|
||||||
|
|
||||||
//Crazy? You might like Vim keybindings. Only takes effect on restart
|
//Crazy? You might like Vim keybindings. Only takes effect on restart
|
||||||
"emulateVim": false
|
"emulateVim": false
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 20px;
|
top: 20px;
|
||||||
left: ~"calc(50% - 150px)";
|
left: ~"calc(50% - 150px)";
|
||||||
background: lighten(@background, 10%);
|
background: transparent;
|
||||||
color: darken(@foreground, 30%);
|
color: darken(@foreground, 30%);
|
||||||
z-index: 999;
|
z-index: 999;
|
||||||
padding: 4px 0px;
|
padding: 4px 0px;
|
||||||
|
@ -12,23 +12,30 @@
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
|
||||||
|
@paletteBackground: lighten(@background, 10%);
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.main {
|
||||||
|
background: @paletteBackground;
|
||||||
|
padding: 8px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0 12px;
|
margin-top: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
width: 90%;
|
width: 100%;
|
||||||
display: block;
|
display: block;
|
||||||
border: 2px solid #555;
|
border: 2px solid #555;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
margin: 8px auto;
|
margin-top: 8px;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: @foreground;
|
color: @foreground;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
@ -40,6 +47,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.results {
|
.results {
|
||||||
|
background: fade(@paletteBackground, 80%);
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
|
|
112
js/palette.js
112
js/palette.js
|
@ -2,7 +2,7 @@ define([
|
||||||
"sessions",
|
"sessions",
|
||||||
"command",
|
"command",
|
||||||
"editor",
|
"editor",
|
||||||
"settings!menus",
|
"settings!menus,user",
|
||||||
"statusbar",
|
"statusbar",
|
||||||
"dom2"
|
"dom2"
|
||||||
], function(sessions, command, editor, Settings, status) {
|
], function(sessions, command, editor, Settings, status) {
|
||||||
|
@ -44,55 +44,10 @@ define([
|
||||||
this.input = this.element.find("input");
|
this.input = this.element.find("input");
|
||||||
this.resultList = this.element.find(".results");
|
this.resultList = this.element.find(".results");
|
||||||
this.commandMode = false;
|
this.commandMode = false;
|
||||||
|
this.searchAll = false;
|
||||||
this.bindInput();
|
this.bindInput();
|
||||||
};
|
};
|
||||||
Palette.prototype = {
|
Palette.prototype = {
|
||||||
getTabValues: function(tab) {
|
|
||||||
var name = tab.fileName;
|
|
||||||
if (!this.cache[name]) {
|
|
||||||
return this.cacheTab(tab);
|
|
||||||
}
|
|
||||||
var cache = this.cache[name];
|
|
||||||
for (var i = 0; i < cache.length; i++) {
|
|
||||||
if (cache[i].tab == tab) {
|
|
||||||
return cache[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.cacheTab(tab);
|
|
||||||
},
|
|
||||||
cacheTab: function(tab) {
|
|
||||||
//create cache entry
|
|
||||||
var entry = {
|
|
||||||
tab: tab,
|
|
||||||
refs: [],
|
|
||||||
text: tab.getValue()
|
|
||||||
};
|
|
||||||
//create token iterator, search for all references
|
|
||||||
var ti = new TokenIterator(tab, 0);
|
|
||||||
var token;
|
|
||||||
while (token = ti.stepForward()) {
|
|
||||||
if (refTest.test(token.type)) {
|
|
||||||
//this is a match, let's store it as a valid result object
|
|
||||||
var row = ti.getCurrentTokenRow();
|
|
||||||
var col = ti.getCurrentTokenColumn();
|
|
||||||
var line = sanitize(tab.getLine(row));
|
|
||||||
entry.refs.push({
|
|
||||||
tab: tab,
|
|
||||||
line: row,
|
|
||||||
label: token.value,
|
|
||||||
sublabel: line,
|
|
||||||
column: col
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var name = tab.fileName;
|
|
||||||
if (!this.cache[name]) {
|
|
||||||
this.cache[name] = [ entry ];
|
|
||||||
} else {
|
|
||||||
this.cache[name].push(entry);
|
|
||||||
}
|
|
||||||
return entry;
|
|
||||||
},
|
|
||||||
bindInput: function() {
|
bindInput: function() {
|
||||||
var input = this.input;
|
var input = this.input;
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -104,6 +59,7 @@ define([
|
||||||
input.on("keydown", function(e) {
|
input.on("keydown", function(e) {
|
||||||
if (e.keyCode == 27) {
|
if (e.keyCode == 27) {
|
||||||
sessions.restoreLocation();
|
sessions.restoreLocation();
|
||||||
|
editor.clearSelection();
|
||||||
return input.blur();
|
return input.blur();
|
||||||
}
|
}
|
||||||
if (e.keyCode == 13) {
|
if (e.keyCode == 13) {
|
||||||
|
@ -159,6 +115,53 @@ define([
|
||||||
menuWalker(menus);
|
menuWalker(menus);
|
||||||
this.results = results;
|
this.results = results;
|
||||||
},
|
},
|
||||||
|
getTabValues: function(tab) {
|
||||||
|
var name = tab.fileName;
|
||||||
|
if (!this.cache[name]) {
|
||||||
|
return this.cacheTab(tab);
|
||||||
|
}
|
||||||
|
var cache = this.cache[name];
|
||||||
|
for (var i = 0; i < cache.length; i++) {
|
||||||
|
if (cache[i].tab == tab) {
|
||||||
|
return cache[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.cacheTab(tab);
|
||||||
|
},
|
||||||
|
cacheTab: function(tab) {
|
||||||
|
//create cache entry
|
||||||
|
var entry = {
|
||||||
|
tab: tab,
|
||||||
|
refs: [],
|
||||||
|
text: tab.getValue()
|
||||||
|
};
|
||||||
|
//create token iterator, search for all references
|
||||||
|
var ti = new TokenIterator(tab, 0);
|
||||||
|
var token;
|
||||||
|
while (token = ti.stepForward()) {
|
||||||
|
if (refTest.test(token.type)) {
|
||||||
|
//this is a match, let's store it as a valid result object
|
||||||
|
var row = ti.getCurrentTokenRow();
|
||||||
|
var col = ti.getCurrentTokenColumn();
|
||||||
|
var line = sanitize(tab.getLine(row));
|
||||||
|
entry.refs.push({
|
||||||
|
tab: tab,
|
||||||
|
line: row,
|
||||||
|
value: token.value,
|
||||||
|
label: tab.fileName + ":" + row,
|
||||||
|
sublabel: line,
|
||||||
|
column: col
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var name = tab.fileName;
|
||||||
|
if (!this.cache[name]) {
|
||||||
|
this.cache[name] = [ entry ];
|
||||||
|
} else {
|
||||||
|
this.cache[name].push(entry);
|
||||||
|
}
|
||||||
|
return entry;
|
||||||
|
},
|
||||||
findLocations: function(query) {
|
findLocations: function(query) {
|
||||||
var file = re.file.test(query) && re.file.exec(query)[1];
|
var file = re.file.test(query) && re.file.exec(query)[1];
|
||||||
var line = re.line.test(query) && Number(re.line.exec(query)[1]) - 1;
|
var line = re.line.test(query) && Number(re.line.exec(query)[1]) - 1;
|
||||||
|
@ -174,9 +177,13 @@ define([
|
||||||
tabs = sessions.getAllTabs().filter(function(tab) {
|
tabs = sessions.getAllTabs().filter(function(tab) {
|
||||||
return fuzzyFile.test(tab.fileName);
|
return fuzzyFile.test(tab.fileName);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
if (this.searchAll) {
|
||||||
|
tabs = sessions.getAllTabs();
|
||||||
} else {
|
} else {
|
||||||
tabs = [ sessions.getCurrent() ];
|
tabs = [ sessions.getCurrent() ];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tabs = tabs.map(function(t) {
|
tabs = tabs.map(function(t) {
|
||||||
return {
|
return {
|
||||||
|
@ -225,7 +232,7 @@ define([
|
||||||
if (results.length >= 10) return;
|
if (results.length >= 10) return;
|
||||||
var refs = self.getTabValues(t.tab).refs;
|
var refs = self.getTabValues(t.tab).refs;
|
||||||
for (var i = 0; i < refs.length; i++) {
|
for (var i = 0; i < refs.length; i++) {
|
||||||
if (crawl.test(refs[i].label)) {
|
if (crawl.test(refs[i].value)) {
|
||||||
var len = results.push(refs[i]);
|
var len = results.push(refs[i]);
|
||||||
if (len > 10) return;
|
if (len > 10) return;
|
||||||
}
|
}
|
||||||
|
@ -241,7 +248,10 @@ define([
|
||||||
sessions.raiseBlurred(current.tab);
|
sessions.raiseBlurred(current.tab);
|
||||||
if (current.line) {
|
if (current.line) {
|
||||||
editor.clearSelection();
|
editor.clearSelection();
|
||||||
editor.moveCursorTo(current.line, 0);
|
editor.moveCursorTo(current.line, current.column || 0);
|
||||||
|
if (current.column) {
|
||||||
|
editor.execCommand("selectwordright");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -259,14 +269,14 @@ define([
|
||||||
},
|
},
|
||||||
activate: function(mode) {
|
activate: function(mode) {
|
||||||
this.results = [];
|
this.results = [];
|
||||||
|
this.cache = {};
|
||||||
this.selected = 0;
|
this.selected = 0;
|
||||||
this.input.value = "";
|
this.searchAll = Settings.get("user").searchAllFiles;
|
||||||
this.commandMode = mode == "command";
|
this.commandMode = mode == "command";
|
||||||
this.input.value = modes[mode] || "";
|
this.input.value = modes[mode] || "";
|
||||||
this.render();
|
this.render();
|
||||||
this.element.classList.add("active");
|
this.element.classList.add("active");
|
||||||
this.input.focus();
|
this.input.focus();
|
||||||
this.cache = {};
|
|
||||||
},
|
},
|
||||||
deactivate: function() {
|
deactivate: function() {
|
||||||
this.element.classList.remove("active");
|
this.element.classList.remove("active");
|
||||||
|
|
|
@ -23,8 +23,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="palette">
|
<div class="palette">
|
||||||
|
<div class="main">
|
||||||
<h1 class="mode"></h1>
|
<h1 class="mode"></h1>
|
||||||
<input class="request"></input>
|
<input class="request"></input>
|
||||||
|
</div>
|
||||||
<ul class="results"></ul>
|
<ul class="results"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "Caret",
|
"name": "Caret",
|
||||||
"description": "Professional text editing for Chrome and Chrome OS",
|
"description": "Professional text editing for Chrome and Chrome OS",
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"icons": {
|
"icons": {
|
||||||
"128": "icon-128-2.png"
|
"128": "icon-128-2.png"
|
||||||
|
|
Loading…
Reference in a new issue