1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-14 15:55:47 +01:00

Merge branch 'master' of djk@vimperator.org:/git/vimperator/liberator

This commit is contained in:
Doug Kearns
2008-12-04 14:47:21 +11:00
3 changed files with 74 additions and 53 deletions

View File

@@ -257,7 +257,7 @@ const liberator = (function () //{{{
"Execute the specified menu item from the command line", "Execute the specified menu item from the command line",
function (args) function (args)
{ {
let args = args.string; args = args.string;
let items = getMenuItems(); let items = getMenuItems();
if (!items.some(function (i) i.fullMenuPath == args)) if (!items.some(function (i) i.fullMenuPath == args))

View File

@@ -105,7 +105,7 @@ const modes = (function () //{{{
case modes.COMMAND_LINE: case modes.COMMAND_LINE:
// clean up for HINT mode // clean up for HINT mode
if (modes.extended & modes.HINTS) if (modes.extended & modes.HINTS)
hints.hide(); hints.hide();
commandline.close(); commandline.close();
break; break;
} }
@@ -180,12 +180,12 @@ const modes = (function () //{{{
// if a main mode is set, the extended is always cleared // if a main mode is set, the extended is always cleared
if (typeof mainMode === "number") if (typeof mainMode === "number")
{ {
if (!silent && mainMode != main)
handleModeChange(main, mainMode);
main = mainMode; main = mainMode;
if (!extendedMode) if (!extendedMode)
extended = modes.NONE; extended = modes.NONE;
if (!silent && mainMode != main)
handleModeChange(main, mainMode);
} }
if (typeof extendedMode === "number") if (typeof extendedMode === "number")
extended = extendedMode; extended = extendedMode;

View File

@@ -134,9 +134,14 @@ function CommandLine() //{{{
this.editor.selection.focusNode.textContent = commandWidget.value; this.editor.selection.focusNode.textContent = commandWidget.value;
// Reset the caret to one position after the completion. // Reset the caret to one position after the completion.
let range = this.editor.selection.getRangeAt(0); this.caret = this.prefix.length + completion.length;
range.setStart(range.startContainer, this.prefix.length + completion.length); },
range.collapse(true);
get caret() this.editor.selection.focusOffset,
set caret(offset)
{
commandWidget.selectionStart = offset;
commandWidget.selectionEnd = offset;
}, },
get start() this.context.allItems.start, get start() this.context.allItems.start,
@@ -154,40 +159,72 @@ function CommandLine() //{{{
full: this.wildmode.checkHas(this.wildtype, "full") full: this.wildmode.checkHas(this.wildtype, "full")
}), }),
complete: function (show, tabPressed)
{
this.context.reset();
this.context.tabPressed = tabPressed;
liberator.triggerCallback("complete", currentExtendedMode, this.context);
this.reset(show, tabPressed);
},
preview: function preview() preview: function preview()
{ {
// This will only work with autocomplete. if (this.wildtype < 0 || this.suffix || !this.items.length)
if (!options.get("wildoptions").has("auto") || !completions)
return; return;
this.previewClear();
if (this.type.longest && !this.suffix) let substring = "";
switch (this.wildtype.replace(/.*:/, ""))
{ {
let start = commandWidget.selectionStart; case "":
let substring = this.substring; substring = this.items[0].text;
break;
// Don't show 1-character substrings unless we've just hit backspace case "longest":
if (substring.length < 2 && (!this.lastSubstring || this.lastSubstring.indexOf(substring) != 0)) if (this.items.length > 1)
return; {
this.lastSubstring = substring; substring = this.substring;
// Chop off the bits we already have. break;
substring = substring.substr(completions.value.length); }
// Fallthrough
// highlight="Preview" won't work in the editor. case "full":
let node = util.xmlToDom(<span style={highlight.get("Preview").value}>{substring}</span>, let item = this.items[this.selected != null ? this.selected + 1 : 0];
document); if (item)
this.editor.insertNode(node, this.editor.rootElement, 1); substring = item.text;
commandWidget.selectionStart = commandWidget.selectionEnd = start; break;
} }
// Don't show 1-character substrings unless we've just hit backspace
if (substring.length < 2 && (!this.lastSubstring || this.lastSubstring.indexOf(substring) != 0))
return;
this.lastSubstring = substring;
let value = this.completion;
if (util.compareIgnoreCase(value, substring.substr(0, value.length)))
return;
substring = substring.substr(value.length);
this.removeSubstring = substring;
// highlight="Preview" won't work in the editor.
let node = util.xmlToDom(<span style={highlight.get("Preview").value}>{substring}</span>,
document);
let start = this.caret;
this.editor.insertNode(node, this.editor.rootElement, 1);
this.caret = start;
}, },
previewClear: function previewClear() previewClear: function previewClear()
{ {
try let node = this.editor.rootElement.firstChild;
if (node && node.nextSibling)
this.editor.deleteNode(node.nextSibling);
else if (this.removeSubstring)
{ {
let node = this.editor.rootElement; let str = this.removeSubstring;
this.editor.deleteNode(node.firstChild.nextSibling); let cmd = commandWidget.value;
if (cmd.substr(cmd.length - str.length) == str)
commandWidget.value = cmd.substr(0, cmd.length - str.length);
} }
catch (e) {} delete this.removeSubstring;
}, },
reset: function reset(show) reset: function reset(show)
@@ -203,7 +240,6 @@ function CommandLine() //{{{
{ {
this.itemList.reset(); this.itemList.reset();
this.select(this.RESET); this.select(this.RESET);
this.itemList.show();
this.wildIndex = 0; this.wildIndex = 0;
} }
@@ -249,12 +285,7 @@ function CommandLine() //{{{
{ {
// Check if we need to run the completer. // Check if we need to run the completer.
if (this.context.waitingForTab || this.wildIndex == -1) if (this.context.waitingForTab || this.wildIndex == -1)
{ this.complete(true, true);
this.context.reset();
this.context.tabPressed = true;
liberator.triggerCallback("complete", currentExtendedMode, this.context);
this.reset(true);
}
if (this.items.length == 0) if (this.items.length == 0)
{ {
@@ -292,6 +323,7 @@ function CommandLine() //{{{
completionList.show(); completionList.show();
this.wildIndex = Math.max(0, Math.min(this.wildtypes.length - 1, this.wildIndex + 1)); this.wildIndex = Math.max(0, Math.min(this.wildtypes.length - 1, this.wildIndex + 1));
this.preview();
statusTimer.tell(); statusTimer.tell();
} }
@@ -311,9 +343,7 @@ function CommandLine() //{{{
var autocompleteTimer = new util.Timer(201, 300, function autocompleteTell(tabPressed) { var autocompleteTimer = new util.Timer(201, 300, function autocompleteTell(tabPressed) {
if (events.feedingKeys || !completions) if (events.feedingKeys || !completions)
return; return;
completions.context.reset(); completions.complete(true, false);
liberator.triggerCallback("complete", currentExtendedMode, completions.context);
completions.reset(true);
completions.itemList.show(); completions.itemList.show();
}); });
@@ -499,7 +529,7 @@ function CommandLine() //{{{
if (lines == 0) if (lines == 0)
lines = 1; lines = 1;
multilineInputWidget.setAttribute("rows", lines.toString()); multilineInputWidget.setAttribute("rows", String(lines));
} }
// used for the :echo[err] commands // used for the :echo[err] commands
@@ -1542,18 +1572,7 @@ function ItemList(id) //{{{
clear: function clear() { this.setItems(); doc.body.innerHTML = ""; }, clear: function clear() { this.setItems(); doc.body.innerHTML = ""; },
hide: function hide() { container.collapsed = true; }, hide: function hide() { container.collapsed = true; },
show: function show() show: function show() { container.collapsed = false; },
{
/* FIXME: Should only happen with autocomplete,
* possibly only with async entries.
*/
if (container.collapsed)
{
minHeight = 0;
setTimeout(function () { fill(null); }, 0);
}
container.collapsed = false;
},
visible: function visible() !container.collapsed, visible: function visible() !container.collapsed,
reset: function () reset: function ()
@@ -1566,6 +1585,8 @@ function ItemList(id) //{{{
// if @param selectedItem is given, show the list and select that item // if @param selectedItem is given, show the list and select that item
setItems: function setItems(newItems, selectedItem) setItems: function setItems(newItems, selectedItem)
{ {
if (container.collapsed)
minHeight = 0;
startIndex = endIndex = selIndex = -1; startIndex = endIndex = selIndex = -1;
items = newItems; items = newItems;
this.reset(); this.reset();