Skip to content

Commit

Permalink
fixed autocapitalize cursor issue
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kharbat committed Feb 20, 2017
1 parent 3d94765 commit 980778c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/crate/crash/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ 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()):
if self.last_changed and self.is_prefix(current_line[:cursor_position].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)
self.last_changed = current_line
buffer.insert_text(new_line, overwrite=False, move_cursor=True, fire_event=False)
self.last_changed = current_line[:cursor_position]

def keyword_replacer(self, match):
if match.group(0).lower() in SQLCompleter.keywords:
Expand Down

0 comments on commit 980778c

Please sign in to comment.