Skip to content

Commit 2745de8

Browse files
Merge pull request #20 from ThisIs-Developer/copilot/fix-tab-key-behavior-editor
Fix Tab key to insert indentation instead of changing focus
2 parents 177805d + 5abab83 commit 2745de8

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

script.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ document.addEventListener("DOMContentLoaded", function () {
8585
});
8686
};
8787

88-
initMermaid();
88+
try {
89+
initMermaid();
90+
} catch (e) {
91+
console.warn("Mermaid initialization failed:", e);
92+
}
8993

9094
const markedOptions = {
9195
gfm: true,
@@ -712,6 +716,30 @@ This is a fully client-side application. Your content never leaves your browser
712716
});
713717

714718
markdownEditor.addEventListener("input", debouncedRender);
719+
720+
// Tab key handler to insert indentation instead of moving focus
721+
markdownEditor.addEventListener("keydown", function(e) {
722+
if (e.key === 'Tab') {
723+
e.preventDefault();
724+
725+
const start = this.selectionStart;
726+
const end = this.selectionEnd;
727+
const value = this.value;
728+
729+
// Insert 2 spaces
730+
const indent = ' '; // 2 spaces
731+
732+
// Update textarea value
733+
this.value = value.substring(0, start) + indent + value.substring(end);
734+
735+
// Update cursor position
736+
this.selectionStart = this.selectionEnd = start + indent.length;
737+
738+
// Trigger input event to update preview
739+
this.dispatchEvent(new Event('input'));
740+
}
741+
});
742+
715743
editorPane.addEventListener("scroll", syncEditorToPreview);
716744
previewPane.addEventListener("scroll", syncPreviewToEditor);
717745
toggleSyncButton.addEventListener("click", toggleSyncScrolling);

0 commit comments

Comments
 (0)