Skip to content

Commit

Permalink
Fix misfiring backspace indentation pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Apr 11, 2021
1 parent 718b10f commit bc2be15
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/useEditable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ export const useEditable = (
'' + opts!.indentation;
}

const indentRe = new RegExp(
`^(?:${' '.repeat(opts!.indentation || 0)}|\\t)`
);
const indentPattern = `${' '.repeat(opts!.indentation || 0)}`;
const indentRe = new RegExp(`^(?:${indentPattern})`);
const blanklineRe = new RegExp(`^(?:${indentPattern})*(${indentPattern})$`);

let _trackStateTimestamp: number;
const trackState = (ignoreTimestamp?: boolean) => {
Expand Down Expand Up @@ -415,8 +415,8 @@ export const useEditable = (
edit.insert('', 0);
} else {
const position = getPosition(element);
const match = indentRe.exec(position.content);
edit.insert('', match ? -match[0].length : -1);
const match = blanklineRe.exec(position.content);
edit.insert('', match ? -match[1].length : -1);
}
} else if (opts!.indentation && event.key === 'Tab') {
event.preventDefault();
Expand Down

0 comments on commit bc2be15

Please sign in to comment.