Add completion, browser integration, and workspace improvements
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import { editorSession } from "./sessions";
|
||||
import { registerSelection } from "./selection";
|
||||
import { monacoChrome } from "./monacoChrome";
|
||||
import { connectMonacoCompletion } from "$lib/completion/monaco";
|
||||
import { markdownMenu } from "./markdownMenu";
|
||||
import type { TableContextActions } from "./tableCellActions";
|
||||
|
||||
@@ -85,6 +86,7 @@
|
||||
let releaseSelection: (() => void) | undefined;
|
||||
let menu: ReturnType<typeof markdownMenu> | undefined;
|
||||
let releaseDrop: (() => void) | undefined;
|
||||
let releaseCompletion: (() => void) | undefined;
|
||||
const listeners: { dispose(): void }[] = [];
|
||||
void import("./monacoEnv").then(({ monaco }) => {
|
||||
if (cancelled || !el.isConnected) {
|
||||
@@ -144,6 +146,7 @@
|
||||
listeners.push(model.onDidChangeContent(() => menu?.close(false)));
|
||||
}
|
||||
const documentId = untrack(() => buffer.id);
|
||||
releaseCompletion = connectMonacoCompletion(monaco, view, documentId, markdown);
|
||||
releaseSelection = registerSelection(documentId, () => view.getSelections()?.map(range => model.getValueInRange(range)).join("\n") || "");
|
||||
if (session.view) view.restoreViewState(session.view);
|
||||
ready += 1;
|
||||
@@ -160,6 +163,7 @@
|
||||
const view = editor;
|
||||
if (view && session) session.view = view.saveViewState();
|
||||
contentListener?.dispose();
|
||||
releaseCompletion?.();
|
||||
releaseSelection?.();
|
||||
menu?.destroy();
|
||||
releaseDrop?.();
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
import type { TableContextActions } from "./tableCellActions";
|
||||
import { markdownMenu } from "./markdownMenu";
|
||||
import { tableNavigation } from "./tableNavigation";
|
||||
import { completionExtension } from "$lib/completion/codemirror";
|
||||
|
||||
type Props = {
|
||||
buffer: OpenBuffer;
|
||||
@@ -138,6 +139,7 @@
|
||||
if (model.getValue() !== lastValue) model.setValue(lastValue);
|
||||
model.pushStackElement();
|
||||
const extensions = [
|
||||
completionExtension(current.id),
|
||||
EditorState.lineSeparator.of(model.getEOL()),
|
||||
markdown({ base: markdownLanguage, extensions: [noteFormats] }),
|
||||
// Rich cell serialization can change delimiters away from the caret.
|
||||
|
||||
@@ -208,7 +208,10 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
|
||||
return [imageSource, StateField.define<DecorationSet>({
|
||||
create: build,
|
||||
update(value, transaction) {
|
||||
return transaction.docChanged || transaction.selection || transaction.effects.some(effect => effect.is(refreshImages) || effect.is(editImageSource)) ? build(transaction.state, value.map(transaction.changes)) : value;
|
||||
return transaction.docChanged || transaction.selection
|
||||
|| syntaxTree(transaction.startState) !== syntaxTree(transaction.state)
|
||||
|| transaction.effects.some(effect => effect.is(refreshImages) || effect.is(editImageSource))
|
||||
? build(transaction.state, value.map(transaction.changes)) : value;
|
||||
},
|
||||
provide: field => [EditorView.decorations.from(field), EditorView.atomicRanges.of(view => view.state.field(field).update({
|
||||
filter: (_from, _to, decoration) => decoration.spec.atomic === true,
|
||||
|
||||
Reference in New Issue
Block a user