VimHandler activates in source (edit) mode only. Two modes: - Insert: standard typing, Esc enters normal mode - Normal: vim navigation and editing, i/a/o/O enter insert Normal mode commands: h/j/k/l: cursor movement w/b: word forward/back 0/$: line start/end gg/G: document start/end i/a/o/O: enter insert mode x: delete char dd: delete line u: undo Ctrl+r: redo
34 lines
972 B
TypeScript
34 lines
972 B
TypeScript
import { Window } from 'happy-dom';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
let _window: any;
|
|
|
|
export function getWindow(): any {
|
|
if (!_window) {
|
|
_window = new Window({ url: 'http://localhost' });
|
|
(global as any).window = _window;
|
|
(global as any).document = _window.document;
|
|
(global as any).HTMLElement = _window.HTMLElement;
|
|
(global as any).Node = _window.Node;
|
|
(global as any).NodeFilter = _window.NodeFilter;
|
|
|
|
const bundle = fs.readFileSync(
|
|
path.join(__dirname, '..', 'dist', 'ribbit', 'ribbit.js'), 'utf8'
|
|
);
|
|
_window.eval(bundle.replace('var ribbit =', 'window.ribbit ='));
|
|
}
|
|
return _window;
|
|
}
|
|
|
|
export function ribbit(): any {
|
|
const w = getWindow();
|
|
const r = w.ribbit;
|
|
r.window = w;
|
|
return r;
|
|
}
|
|
|
|
export function resetDOM(content = 'test'): void {
|
|
getWindow().document.body.innerHTML = `<article id="ribbit">${content}</article>`;
|
|
}
|