Skip to content

Commit

Permalink
small improvements in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
annekekleppe committed Oct 1, 2024
1 parent 9798e83 commit 92298fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Deselection can be done by:
2. The component that is clicked should be selected.

**In all cases the dropdown should be hidden. When this is an action box, the text should be emptied. In case of a
select box, the current text should be saved, even if it is incorrect.****
select box, the current text should be saved, but not if it is incorrect.****

## Translation into code

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ export class TextComponentHelper {
} else {
this._dispatcher('showDropdown');
this.getCaretPosition(event);
let endPosition: number = this._getText().length;
// todo this code is the same as in handleBackspace, make it a private method
// for now: the console messages make clearer what is happening
if (this._from < endPosition || (this._from !== this._to)) { // some chars remain at the right, or several chars are selected
if (this._from < this._getText().length || (this._from !== this._to)) { // some chars remain at the right, or several chars are selected
// No need to adjust the caret position, the char will be deleted *after* the caret
console.log(`handleDelete, caret: ${this._from}-${this._to}`);
// Without propagation but with event Default, the browser handles which char(s) to be deleted.
// With event.ctrlKey: delete text from caret to start, is also handled by the browser.
Expand All @@ -91,10 +89,12 @@ export class TextComponentHelper {
handleBackSpace(event: KeyboardEvent, editor: FreEditor) {
this._dispatcher('showDropdown');
this.getCaretPosition(event);
let endPosition: number = 0;
// todo this code is the same as in handleDelete, make it a private method
// for now: the console messages make clearer what is happening
if (this._from > endPosition || (this._from !== this._to)) { // some chars remain at the left, or several chars are selected
if (this._from > 0 || (this._from !== this._to)) { // some chars remain at the left, or several chars are selected
if (this._from === this._to) {
// Adjust the caret position to take into account the deleted char, because it is *before* the current caret
this._from -= 1;
this._to -= 1;
} // else: the deleted chars are *after* this._from, therefore no need to adjust the caret.
console.log(`handleBackSpace, caret: ${this._from}-${this._to}`);
// Without propagation but with event Default, the browser handles which char(s) to be deleted.
// With event.ctrlKey: delete text from caret to start, is also handled by the browser.
Expand Down

0 comments on commit 92298fa

Please sign in to comment.