community icon indicating copy to clipboard operation
community copied to clipboard

Fixed TextInput _move_cursor_word_left / right for wrapped words

Open Alspb opened this issue 4 years ago • 2 comments

Fixed two bugs:

  1. TextInput and CodeNavigationBehavior _move_cursor_word_left , _move_cursor_word_right methods move cursor only to the beginning / end of the current line for wrapped words, not to the beginning / end of the word itself.
  2. For the case below CodeNavigationBehavior._move_cursor_word_right (i.e. Ctrl + Right shortcut) doesn't do anything at all. CodeInput move word right bug

Note:

CodeNavigationBehavior._move_cursor_word_right moves cursor to the beginning of the next word. So for the following example CodeInput move word right note ('a...a' and 'b...b' are different words) A) When cursor is at the end of the first line it should move to the beginning of the second line (i.e. beginning of the word 'b...b'), B) When cursor is at the beginning of the second line it should move to the end of the text. But since _move_cursor_word_left gets cursor index as an argument, it acts the same in both cases above (because cursor indices are the same). That's why currently in case B cursor also doesn't move at all. The direct way to fix it is to change cursor index argument to cursor position. But not sure that it's worth it taking backward compatibility into account. So in the fix for both cases _move_cursor_word_left acts as in the case B. But it's not a big deal, cause in case A cursor is already almost at the beginning of the word 'b...b'.

Maintainer merge checklist

  • [ ] Title is descriptive/clear for inclusion in release notes.
  • [ ] Applied a Component: xxx label.
  • [ ] Applied the api-deprecation or api-break label.
  • [ ] Applied the release-highlight label to be highlighted in release notes.
  • [ ] Added to the milestone version it was merged into.
  • [ ] Unittests are included in PR.
  • [ ] Properly documented, including versionadded, versionchanged as needed.

Alspb avatar Oct 01 '21 06:10 Alspb

As I understand, the fail is caused by the line import kivy.uix.textinput as textinput in codenavigation.py. Does anyone have any idea why?

For now I see only two alternatives: A) Set

self.FL_IS_LINEBREAK = FL_IS_LINEBREAK
self.FL_IS_WORDBREAK = FL_IS_WORDBREAK

inside TextInput.__init__ and use self.FL_IS_LINEBREAK, self.FL_IS_WORDBREAK in codenavigation.py, but it seems a bit odd. B) Move _move_cursor_word_left and _move_cursor_word_right to CodeInput class, and therefore remove codenavigation.py (as it becomes empty). Actually currently I don't see any disadvantages.

Alspb avatar Oct 19 '21 04:10 Alspb

Decided to put FL_IS_LINEBREAK, FL_IS_WORDBREAK into CodeInput attributes.

Alspb avatar Jan 15 '22 08:01 Alspb