Skip to content

Commit

Permalink
Some small bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
j-wing committed Oct 24, 2019
1 parent 9188124 commit 8233f8d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,15 @@ class App extends React.Component<AppProps, AppState> {
if (e.key === "Enter") {
e.preventDefault();
this.setState((props, state) => {
let newNote = this.state.note.addLine(noteRow.getIndentedUnits());
let note = this.state.note;
let newNote = note.addLine(noteRow.getIndentedUnits());

return { note: this.state.note, focusedNoteRowId: newNote.id }
return { note: note, focusedNoteRowId: newNote.id }
});
return false;
} else if (e.key === "Backspace") {
// Since we're catching the keydown event, if we don't call preventDefault,
// a character will get deleted on the line that gets focus.
e.preventDefault();

let focusedRow = this.state.note.getLine(this.state.focusedNoteRowId);
if (focusedRow !== undefined && focusedRow.isEmpty()) {
if (focusedRow !== undefined && focusedRow.isEmpty() && this.state.note.getLines().length > 1) {
let nextFocusedRowId = this.state.note.getPreviousRowId(this.state.focusedNoteRowId);
this.state.note.deleteRow(this.state.focusedNoteRowId);

Expand All @@ -111,6 +108,11 @@ class App extends React.Component<AppProps, AppState> {
}

NoteContentHandler.updateNote(this.state.note);

// Since we're catching the keydown event, if we don't call preventDefault,
// a character will get deleted on the line that gets focus.
e.preventDefault();

}
} else {
return true;
Expand Down

0 comments on commit 8233f8d

Please sign in to comment.