The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Ctrl+arrow moves the carret one word

These changes was commited to the Birdfont repository Tue, 31 Mar 2015 17:33:59 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Tue, 31 Mar 2015 17:33:59 +0000 (19:33 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Tue, 31 Mar 2015 17:33:59 +0000 (19:33 +0200)
commit beafdc93afb834d69cc4e228bdbf934303635708
tree 97e227858232afd32ba98df530f045fae4ed2b49
parent ce0d6d5eafbf4c7e5c75d7145a501d14fecc6fb6
Ctrl+arrow moves the carret one word

libbirdfont/Renderer/TextArea.vala
--- a/libbirdfont/Renderer/TextArea.vala +++ b/libbirdfont/Renderer/TextArea.vala @@ -528,6 +528,22 @@ } public void move_carret_next () { + unichar c; + + move_carret_one_character (); + + if (KeyBindings.has_ctrl ()) { + while (true) { + c = move_carret_one_character (); + + if (c == '\0' || c == ' ') { + break; + } + } + } + } + + unichar move_carret_one_character () { Paragraph paragraph; int index; unichar c; @@ -536,17 +552,37 @@ paragraph = paragraphs.get (carret.paragraph); index = carret.character_index; + paragraph.text.get_next_char (ref index, out c); if (index >= paragraph.text_length && carret.paragraph + 1 < paragraphs.size) { carret.paragraph++; carret.character_index = 0; + c = ' '; } else { carret.character_index = index; } + + return c; } public void move_carret_previous () { + unichar c; + + move_carret_back_one_character (); + + if (KeyBindings.has_ctrl ()) { + while (true) { + c = move_carret_back_one_character (); + + if (c == '\0' || c == ' ') { + break; + } + } + } + } + + unichar move_carret_back_one_character () { Paragraph paragraph; int index, last_index; unichar c; @@ -571,11 +607,18 @@ if (paragraph.text.has_suffix ("\n")) { carret.character_index -= "\n".length; } + + c = ' '; + } else if (last_index > 0) { + carret.character_index = last_index; } else { - carret.character_index = (last_index) > 0 ? last_index : 0; + carret.character_index = 0; + c = ' '; } return_if_fail (0 <= carret.paragraph < paragraphs.size); + + return c; } public void move_carret_next_row () {