From 076c983742b2550b2f7a37d2836dc65c8753bf87 Mon Sep 17 00:00:00 2001 From: James Prevett Date: Sun, 13 Oct 2024 17:00:42 -0500 Subject: [PATCH] Added editor tab key support --- src/editor.ts | 16 ++++++++++++++++ src/index.ts | 1 + 2 files changed, 17 insertions(+) create mode 100644 src/editor.ts diff --git a/src/editor.ts b/src/editor.ts new file mode 100644 index 0000000..7d840f5 --- /dev/null +++ b/src/editor.ts @@ -0,0 +1,16 @@ +import $ from 'jquery'; + +$('#editor .content').on('keydown', e => { + if (e.key != 'Tab') { + return; + } + e.preventDefault(); + + const start = e.target.selectionStart; + + // set textarea value to: text before caret + tab + text after caret + e.target.value = e.target.value.slice(0, start) + '\t' + e.target.value.slice(e.target.selectionEnd); + + // put caret at right position again + e.target.selectionStart = e.target.selectionEnd = start + 1; +}); diff --git a/src/index.ts b/src/index.ts index add7eed..c2eee3d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import './styles.css'; import $ from 'jquery'; import './config.js'; +import './editor.js'; import { update, location } from './explorer.js'; import './shell.js'; import { cwd, isAbsolute } from '@zenfs/core/emulation/path.js';