//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
-"use strict";
+/* use strict */
var MOW = Module("mow", {
init: function init() {
if (modes.have(modes.OUTPUT_MULTILINE)) {
this.resize(true);
- if (options["more"] && this.isScrollable(1)) {
+ if (options["more"] && this.canScroll(1))
// start the last executed command's output at the top of the screen
- let elements = this.document.getElementsByClassName("ex-command-output");
- elements[elements.length - 1].scrollIntoView(true);
- }
+ DOM(this.document.body.lastElementChild).scrollIntoView(true);
else
this.body.scrollTop = this.body.scrollHeight;
events.listen(window, this, "windowEvents");
modules.mow = this;
- let fontSize = util.computedStyle(document.documentElement).fontSize;
+ let fontSize = DOM(document.documentElement).style.fontSize;
styles.system.add("font-size", "dactyl://content/buffer.xhtml",
"body { font-size: " + fontSize + "; } \
html|html > xul|scrollbar { visibility: collapse !important; }",
true);
XML.ignoreWhitespace = true;
- util.overlayWindow(window, {
+ overlay.overlayWindow(window, {
objects: {
eventTarget: this
},
</menupopup>
</popupset>
</window>
- <vbox id={config.commandContainer}>
+ <vbox id={config.ids.commandContainer}>
<vbox class="dactyl-container" id="dactyl-multiline-output-container" hidden="false" collapsed="true">
<iframe id="dactyl-multiline-output" src="dactyl://content/buffer.xhtml"
flex="1" hidden="false" collapsed="false" contextmenu="dactyl-contextmenu"
__noSuchMethod__: function (meth, args) Buffer[meth].apply(Buffer, [this.body].concat(args)),
get widget() this.widgets.multilineOutput,
- widgets: Class.memoize(function widgets() commandline.widgets),
+ widgets: Class.Memoize(function widgets() commandline.widgets),
- body: Class.memoize(function body() this.widget.contentDocument.documentElement),
+ body: Class.Memoize(function body() this.widget.contentDocument.documentElement),
get document() this.widget.contentDocument,
get window() this.widget.contentWindow,
* @param {string} highlightGroup
*/
echo: function echo(data, highlightGroup, silent) {
- let body = this.document.body;
+ let body = DOM(this.document.body);
this.widgets.message = null;
if (!commandline.commandVisible)
if (modes.main != modes.OUTPUT_MULTILINE) {
modes.push(modes.OUTPUT_MULTILINE, null, {
onKeyPress: this.closure.onKeyPress,
+
leave: this.closure(function leave(stack) {
if (stack.pop)
for (let message in values(this.messages))
if (message.leave)
message.leave(stack);
- })
+ }),
+
+ window: this.window
});
this.messages = [];
}
// after interpolated data.
XML.ignoreWhitespace = XML.prettyPrinting = false;
+ highlightGroup = "CommandOutput " + (highlightGroup || "");
+
if (isObject(data) && !isinstance(data, _)) {
this.lastOutput = null;
- var output = util.xmlToDom(<div class="ex-command-output" style="white-space: nowrap" highlight={highlightGroup}/>,
- this.document);
+ var output = DOM(<div style="white-space: nowrap" highlight={highlightGroup}/>,
+ this.document);
data.document = this.document;
try {
- output.appendChild(data.message);
+ output.append(data.message);
}
catch (e) {
util.reportError(e);
this.messages.push(data);
}
else {
- let style = isString(data) ? "pre" : "nowrap";
- this.lastOutput = <div class="ex-command-output" style={"white-space: " + style} highlight={highlightGroup}>{data}</div>;
+ let style = isString(data) ? "pre-wrap" : "nowrap";
+ this.lastOutput = <div style={"white-space: " + style} highlight={highlightGroup}>{data}</div>;
- var output = util.xmlToDom(this.lastOutput, this.document);
+ var output = DOM(this.lastOutput, this.document);
}
// FIXME: need to make sure an open MOW is closed when commands
// that don't generate output are executed
if (!this.visible) {
this.body.scrollTop = 0;
- body.textContent = "";
+ body.empty();
}
- body.appendChild(output);
+ body.append(output);
let str = typeof data !== "xml" && data.message || data;
if (!silent)
- dactyl.triggerObserver("echoMultiline", data, highlightGroup, output);
+ dactyl.triggerObserver("echoMultiline", data, highlightGroup, output[0]);
this._timer.tell();
if (!this.visible)
};
if (event.target instanceof HTMLAnchorElement)
- switch (events.toString(event)) {
+ switch (DOM.Event.stringify(event)) {
case "<LeftMouse>":
openLink(dactyl.CURRENT_TAB);
break;
onKeyPress: function onKeyPress(eventList) {
const KILL = false, PASS = true;
- if (options["more"] && mow.isScrollable(1))
+ if (options["more"] && mow.canScroll(1))
this.updateMorePrompt(false, true);
else {
modes.pop();
let doc = this.widget.contentDocument;
- let availableHeight = config.outputHeight;
+ let trim = this.spaceNeeded;
+ let availableHeight = config.outputHeight - trim;
if (this.visible)
availableHeight += parseFloat(this.widgets.mowContainer.height || 0);
availableHeight -= extra || 0;
doc.body.style.minWidth = this.widgets.commandbar.commandline.scrollWidth + "px";
- this.widgets.mowContainer.height = Math.min(doc.body.clientHeight, availableHeight) + "px";
- this.timeout(function ()
- this.widgets.mowContainer.height = Math.min(doc.body.clientHeight, availableHeight) + "px",
- 0);
+
+ function adjust() {
+ let wantedHeight = doc.body.clientHeight;
+ this.widgets.mowContainer.height = Math.min(wantedHeight, availableHeight) + "px",
+ this.wantedHeight = Math.max(0, wantedHeight - availableHeight);
+ }
+ adjust.call(this);
+ this.timeout(adjust);
doc.body.style.minWidth = "";
},
get spaceNeeded() {
- let rect = this.widgets.commandbar.commandline.getBoundingClientRect();
- let offset = rect.bottom - window.innerHeight;
- return Math.max(0, offset);
+ if (DOM("#dactyl-bell", document).isVisible)
+ return 0;
+ return Math.max(0, DOM("#" + config.ids.commandContainer, document).rect.bottom
+ - window.innerHeight);
},
/**
if (showHelp)
this.widgets.message = ["MoreMsg", _("mow.moreHelp")];
- else if (force || (options["more"] && Buffer.isScrollable(elem, 1)))
+ else if (force || (options["more"] && Buffer.canScroll(elem, 1)))
this.widgets.message = ["MoreMsg", _("mow.more")];
else
this.widgets.message = ["Question", _("mow.continue")];
if (!value && elem && elem.contentWindow == document.commandDispatcher.focusedWindow) {
let focused = content.document.activeElement;
- if (Events.isInputElement(focused))
+ if (focused && Events.isInputElement(focused))
focused.blur();
document.commandDispatcher.focusedWindow = content;
})
}, {
}, {
+ modes: function initModes() {
+ modes.addMode("OUTPUT_MULTILINE", {
+ description: "Active when the multi-line output buffer is open",
+ bases: [modes.NORMAL]
+ });
+ },
mappings: function initMappings() {
const PASS = true;
const DROP = false;
mow.echo(mow.lastOutput, "Normal");
});
+ mappings.add([modes.OUTPUT_MULTILINE],
+ ["<Esc>", "<C-[>"],
+ "Return to the previous mode",
+ function () { modes.pop(null, { fromEscape: true }); });
+
let bind = function bind(keys, description, action, test, default_) {
mappings.add([modes.OUTPUT_MULTILINE],
keys, description,
bind(["j", "<C-e>", "<Down>"], "Scroll down one line",
function ({ count }) { mow.scrollVertical("lines", 1 * (count || 1)); },
- function () mow.isScrollable(1), BEEP);
+ function () mow.canScroll(1), BEEP);
bind(["k", "<C-y>", "<Up>"], "Scroll up one line",
function ({ count }) { mow.scrollVertical("lines", -1 * (count || 1)); },
- function () mow.isScrollable(-1), BEEP);
+ function () mow.canScroll(-1), BEEP);
bind(["<C-j>", "<C-m>", "<Return>"], "Scroll down one line, exit on last line",
function ({ count }) { mow.scrollVertical("lines", 1 * (count || 1)); },
- function () mow.isScrollable(1), DROP);
+ function () mow.canScroll(1), DROP);
// half page down
bind(["<C-d>"], "Scroll down half a page",
function ({ count }) { mow.scrollVertical("pages", .5 * (count || 1)); },
- function () mow.isScrollable(1), BEEP);
+ function () mow.canScroll(1), BEEP);
bind(["<C-f>", "<PageDown>"], "Scroll down one page",
function ({ count }) { mow.scrollVertical("pages", 1 * (count || 1)); },
- function () mow.isScrollable(1), BEEP);
+ function () mow.canScroll(1), BEEP);
bind(["<Space>"], "Scroll down one page",
function ({ count }) { mow.scrollVertical("pages", 1 * (count || 1)); },
- function () mow.isScrollable(1), DROP);
+ function () mow.canScroll(1), DROP);
bind(["<C-u>"], "Scroll up half a page",
function ({ count }) { mow.scrollVertical("pages", -.5 * (count || 1)); },
- function () mow.isScrollable(-1), BEEP);
+ function () mow.canScroll(-1), BEEP);
bind(["<C-b>", "<PageUp>"], "Scroll up half a page",
function ({ count }) { mow.scrollVertical("pages", -1 * (count || 1)); },
- function () mow.isScrollable(-1), BEEP);
+ function () mow.canScroll(-1), BEEP);
bind(["gg"], "Scroll to the beginning of output",
function () { mow.scrollToPercent(null, 0); });