Skip to content

Commit

Permalink
Added editor tab key support
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Oct 13, 2024
1 parent 331d8bc commit 076c983
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import $ from 'jquery';

$<HTMLTextAreaElement>('#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;
});
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 076c983

Please sign in to comment.