Fork Notesium source and restructure into Go package layout

Initial fork of github.com/alonswartz/notesium into librenotes:
- Source moved to internal/notesium/ (package notesium)
- Thin entry point at cmd/librenotes/main.go
- Module renamed to git.librete.ch/public/librenotes
- main() exposed as notesium.Run()
- LICENSE preserved (MIT), NOTICE added with attribution
- Web assets and completion.bash co-located with embedding code
  to satisfy go:embed path constraints

Closes #3, #34, #35.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-28 21:52:25 +02:00
co-authored by Claude Opus 4.7
parent b816914b9c
commit df9407dd8d
63 changed files with 7391 additions and 0 deletions
+81
View File
@@ -0,0 +1,81 @@
export function initCodeMirrorVimEx(notesiumState) {
CodeMirror.Vim.defineEx('quit', 'q', (cm, cmd) => {
const confirmIfModified = cmd.argString !== '!';
if (cm.quit) cm.quit(confirmIfModified);
});
CodeMirror.Vim.defineEx('wq', '', (cm) => {
if (cm.writequit) cm.writequit();
});
CodeMirror.Vim.defineEx('cmExecCommand', '', (cm, cmd) => {
cm.execCommand(cmd.args[0]);
});
CodeMirror.Vim.map('zo', ':cmExecCommand unfold', 'normal');
CodeMirror.Vim.map('zc', ':cmExecCommand fold', 'normal');
CodeMirror.Vim.map('zR', ':cmExecCommand unfoldAll', 'normal');
CodeMirror.Vim.map('zM', ':cmExecCommand foldAll', 'normal');
CodeMirror.Vim.map('za', ':cmExecCommand toggleFold', 'normal');
CodeMirror.Vim.defineEx('OpenLinkUnderCursor', '', (cm) => {
if (!cm.openlink) return;
const cursor = cm.getCursor();
const lineContent = cm.getLine(cursor.line);
const mdLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
const urlLinkRegex = /(?:https?:\/\/|www\.)[^\s)]+/g;
let match;
let link = null;
while ((match = mdLinkRegex.exec(lineContent)) !== null) {
const start = match.index;
const end = start + match[0].length;
if (cursor.ch >= start && cursor.ch <= end) { link = match[2]; break; }
}
if (!link) {
while ((match = urlLinkRegex.exec(lineContent)) !== null) {
const start = match.index;
const end = start + match[0].length;
if (cursor.ch >= start && cursor.ch <= end) { link = match[0]; break; }
}
}
if (link) cm.openlink(link);
});
CodeMirror.Vim.map('ge', ':OpenLinkUnderCursor', 'normal');
CodeMirror.Vim.map('gx', ':OpenLinkUnderCursor', 'normal');
CodeMirror.Vim.defineEx('BodyKeyEvent', '', (cm, cmd) => {
const key = cmd.args[0];
const code = cmd.args[1];
const ctrlKey = key.startsWith('<C')
cm.display.input.blur();
document.body.focus();
document.body.dispatchEvent(new KeyboardEvent('keydown', { key: key, code: code, ctrlKey: ctrlKey, bubbles: true, cancelable: true, composed: true }));
});
CodeMirror.Vim.map('<Space>', ':BodyKeyEvent <Space> Space', 'normal');
CodeMirror.Vim.map('<C-h>', ':BodyKeyEvent <C-h> KeyH', 'normal');
CodeMirror.Vim.map('<C-l>', ':BodyKeyEvent <C-l> KeyL', 'normal');
CodeMirror.Vim.map('<C-6>', ':BodyKeyEvent <C-o> Digit6', 'normal');
CodeMirror.Vim.map('<C-h>', ':BodyKeyEvent <C-h> KeyH', 'insert');
CodeMirror.Vim.map('<C-l>', ':BodyKeyEvent <C-l> KeyL', 'insert');
CodeMirror.Vim.map('<C-6>', ':BodyKeyEvent <C-6> Digit6', 'insert');
CodeMirror.Vim.defineOption('wrap', notesiumState.editorLineWrapping, 'boolean', [], (value, cm) => {
if (cm) return; // option is global, do nothing for local
if (value === undefined) return notesiumState.editorLineWrapping;
notesiumState.editorLineWrapping = value;
return value;
});
CodeMirror.Vim.defineOption('conceal', notesiumState.editorConcealFormatting, 'boolean', [], (value, cm) => {
if (cm) return; // option is global, do nothing for local
if (value === undefined) return notesiumState.editorConcealFormatting;
notesiumState.editorConcealFormatting = value;
return value;
});
CodeMirror.Vim.defineOption('fold', notesiumState.editorFoldGutter, 'boolean', [], (value, cm) => {
if (cm) return; // option is global, do nothing for local
if (value === undefined) return notesiumState.editorFoldGutter;
notesiumState.editorFoldGutter = value;
return value;
});
}