Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/editor/src/lib/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,25 @@
}}
/>

<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="container"
bind:this={container}
onfocusin={() => {
onpointerdown={() => {
workspace.enable_tab_indent();
}}
onkeydown={(e) => {
if (e.key !== 'Tab') {
workspace.enable_tab_indent();
}
}}
onfocusin={(e) => {
clearTimeout(remove_focus_timeout);
preserve_editor_focus = true;
}}
onfocusout={() => {
workspace.disable_tab_indent();

// Heuristic: user did refocus themmselves if iframe_took_focus
// doesn't happen in the next few miliseconds. Needed
// because else navigations inside the iframe refocus the editor.
Expand Down
20 changes: 18 additions & 2 deletions packages/editor/src/lib/Workspace.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CompileError, CompileOptions, CompileResult } from 'svelte/compiler';
import { EditorState } from '@codemirror/state';
import { Compartment, EditorState } from '@codemirror/state';
import { compile_file } from './compile-worker';
import { BROWSER } from 'esm-env';
import { basicSetup, EditorView } from 'codemirror';
Expand Down Expand Up @@ -51,10 +51,12 @@ function file_type(file: Item) {
return file.name.split('.').pop();
}

const tab_behaviour = new Compartment();

const default_extensions = [
basicSetup,
EditorState.tabSize.of(2),
keymap.of([{ key: 'Tab', run: acceptCompletion }, indentWithTab]),
tab_behaviour.of(keymap.of([{ key: 'Tab', run: acceptCompletion }])),
indentUnit.of('\t'),
theme
];
Expand Down Expand Up @@ -209,6 +211,20 @@ export class Workspace {
return item;
}

disable_tab_indent() {
this.#view?.dispatch({
effects: tab_behaviour.reconfigure(keymap.of([{ key: 'Tab', run: acceptCompletion }]))
});
}

enable_tab_indent() {
this.#view?.dispatch({
effects: tab_behaviour.reconfigure(
keymap.of([{ key: 'Tab', run: acceptCompletion }, indentWithTab])
)
});
}

focus() {
setTimeout(() => {
this.#view?.focus();
Expand Down
Loading