Skip to content

Commit

Permalink
improve tabbig
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Apr 4, 2020
1 parent a0f316e commit 51697c0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions codejar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export class CodeJar {
const s = window.getSelection()!
s.removeAllRanges()

if (pos.start < 0) pos.start = 0
if (pos.end < 0) pos.end = 0

const r = document.createRange()
r.setStart(this.editor, 0)
r.setEnd(this.editor, 0)
Expand Down Expand Up @@ -225,9 +228,10 @@ export class CodeJar {
if (event.shiftKey) {
const before = this.beforeCursor()
let [padding, start,] = findPadding(before)
if (padding.startsWith(this.options.tab)) {
if (padding.length > 0) {
const pos = this.save()
const len = this.options.tab.length
// Remove full length tab or just remaining padding
const len = Math.min(this.options.tab.length, padding.length)
this.restore({start, end: start + len})
document.execCommand("delete")
pos.start -= len
Expand Down

0 comments on commit 51697c0

Please sign in to comment.