Add basic CodeMirror extensions, increase window size, improve foldernav
CSS
This commit is contained in:
parent
3c25204027
commit
02ecfb4bef
|
|
@ -1,10 +1,26 @@
|
||||||
import { Transaction } from "@codemirror/state";
|
import { Transaction, StateEffect } from "@codemirror/state";
|
||||||
import { EditorView, keymap } from "@codemirror/view";
|
import {
|
||||||
|
EditorView,
|
||||||
|
keymap,
|
||||||
|
lineNumbers,
|
||||||
|
highlightSpecialChars,
|
||||||
|
highlightActiveLine,
|
||||||
|
highlightActiveLineGutter,
|
||||||
|
drawSelection,
|
||||||
|
dropCursor,
|
||||||
|
rectangularSelection,
|
||||||
|
crosshairCursor,
|
||||||
|
} from "@codemirror/view";
|
||||||
import { defaultKeymap, undo, redo } from "@codemirror/commands";
|
import { defaultKeymap, undo, redo } from "@codemirror/commands";
|
||||||
import { oneDark } from "@codemirror/theme-one-dark";
|
import { oneDark } from "@codemirror/theme-one-dark";
|
||||||
import { LanguageDescription } from "@codemirror/language";
|
import {
|
||||||
|
LanguageDescription,
|
||||||
|
foldGutter,
|
||||||
|
indentOnInput,
|
||||||
|
bracketMatching,
|
||||||
|
} from "@codemirror/language";
|
||||||
import { languages } from "@codemirror/language-data";
|
import { languages } from "@codemirror/language-data";
|
||||||
import { StateEffect } from "@codemirror/state";
|
import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
|
||||||
|
|
||||||
import { OpenFile } from "./filestate";
|
import { OpenFile } from "./filestate";
|
||||||
|
|
||||||
|
|
@ -44,6 +60,7 @@ export class Editor {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
const kmap = keymap.of([
|
const kmap = keymap.of([
|
||||||
...defaultKeymap,
|
...defaultKeymap,
|
||||||
|
...searchKeymap,
|
||||||
{ key: "Mod-z", run: () => undo(file.target) },
|
{ key: "Mod-z", run: () => undo(file.target) },
|
||||||
{ key: "Mod-shift-z", run: () => redo(file.target) },
|
{ key: "Mod-shift-z", run: () => redo(file.target) },
|
||||||
]);
|
]);
|
||||||
|
|
@ -55,13 +72,33 @@ export class Editor {
|
||||||
fixedHeightEditor,
|
fixedHeightEditor,
|
||||||
kmap,
|
kmap,
|
||||||
EditorView.lineWrapping,
|
EditorView.lineWrapping,
|
||||||
|
lineNumbers(),
|
||||||
|
highlightSpecialChars(),
|
||||||
|
foldGutter(),
|
||||||
|
drawSelection(),
|
||||||
|
dropCursor(),
|
||||||
|
// allowMultipleSelections,
|
||||||
|
indentOnInput(),
|
||||||
|
bracketMatching(),
|
||||||
|
// closeBrackets,
|
||||||
|
// autocompletion,
|
||||||
|
rectangularSelection(),
|
||||||
|
crosshairCursor(),
|
||||||
|
highlightActiveLine(),
|
||||||
|
highlightActiveLineGutter(),
|
||||||
|
highlightSelectionMatches(),
|
||||||
|
// lintKeymap,
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
const language = LanguageDescription.matchFilename(languages, file.filePath)?.load().then((Lang) => {
|
const language = LanguageDescription.matchFilename(
|
||||||
let eff = StateEffect.appendConfig.of(Lang);
|
languages,
|
||||||
let tr = this.view.dispatch({effects: [eff]});
|
file.filePath,
|
||||||
});
|
)
|
||||||
|
?.load()
|
||||||
|
.then((Lang) => {
|
||||||
|
let eff = StateEffect.appendConfig.of(Lang);
|
||||||
|
let tr = this.view.dispatch({ effects: [eff] });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get dom() {
|
get dom() {
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ const FsItemView = (tree: FolderTree): HTMLElement => {
|
||||||
if (tree.type === "file")
|
if (tree.type === "file")
|
||||||
return v.p(
|
return v.p(
|
||||||
{
|
{
|
||||||
|
class: "cursor-pointer hover:bg-gray-100",
|
||||||
onclick: async () =>
|
onclick: async () =>
|
||||||
addEditor(await OpenFile.openFile(tree.path)),
|
addEditor(await OpenFile.openFile(tree.path)),
|
||||||
},
|
},
|
||||||
|
|
@ -55,13 +56,16 @@ const FsItemView = (tree: FolderTree): HTMLElement => {
|
||||||
? v.ul({}, tree.children?.map(FsItemView))
|
? v.ul({}, tree.children?.map(FsItemView))
|
||||||
: v.div({ ariaBusy: true });
|
: v.div({ ariaBusy: true });
|
||||||
const folder = v.details(
|
const folder = v.details(
|
||||||
{ class: "inline", ontoggle: () => (isOpen.val = folder.open) },
|
{
|
||||||
|
class: "flex-auto inline",
|
||||||
|
ontoggle: () => (isOpen.val = folder.open),
|
||||||
|
},
|
||||||
v.summary(tree.name),
|
v.summary(tree.name),
|
||||||
children,
|
children,
|
||||||
);
|
);
|
||||||
|
|
||||||
return v.div(
|
return v.div(
|
||||||
{ class: "flex" },
|
{ class: "cursor-pointer flex hover:bg-gray-100" },
|
||||||
v.span(() => (isOpen.val ? "📂" : "📁")),
|
v.span(() => (isOpen.val ? "📂" : "📁")),
|
||||||
folder,
|
folder,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ if (started) {
|
||||||
const createWindow = () => {
|
const createWindow = () => {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const mainWindow = new BrowserWindow({
|
const mainWindow = new BrowserWindow({
|
||||||
width: 800,
|
width: 1152,
|
||||||
height: 600,
|
height: 720,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, "preload.js"),
|
preload: path.join(__dirname, "preload.js"),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue