Skip to content

Commit

Permalink
Merge 543cd94 into 3d94765
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kharbat committed Feb 17, 2017
2 parents 3d94765 + 543cd94 commit 652425c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -5,6 +5,9 @@ Changes for crash
Unreleased
==========

- Fixed issue that caused the autocapitalization to move the cursor
to the end of the line.

- Automatically capitalize keywords while typing,
e.g. ``select`` -> ``SELECT``

Expand Down
7 changes: 5 additions & 2 deletions src/crate/crash/repl.py
Expand Up @@ -186,16 +186,19 @@ def __call__(self, buffer):
current_line = buffer.document.text
cursor_position = buffer.document.cursor_position


if self.last_changed and self.is_prefix(current_line.lower(), self.last_changed.lower()):
diff = len(self.last_changed) - len(current_line)
current_line = self.last_changed + current_line[diff:]

new_line = re.sub(self.KEYWORD_RE, self.keyword_replacer, current_line)
new_line = re.sub(self.KEYWORD_RE, self.keyword_replacer, \
current_line[:cursor_position])

if new_line != buffer.document.text:
buffer.delete_before_cursor(cursor_position)
buffer.delete(len(new_line) - cursor_position)
buffer.insert_text(new_line, fire_event=False)
buffer.insert_text(new_line, overwrite=False, move_cursor=True,\
fire_event=False)
self.last_changed = current_line

def keyword_replacer(self, match):
Expand Down

0 comments on commit 652425c

Please sign in to comment.