Skip to content

Commit ce04696

Browse files
committed
Do not inset extra quote if there is already one exists
1 parent 91a27a3 commit ce04696

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tern.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ def on_selection_modified_async(self, view):
5454
on_selection_modified(view)
5555

5656
def on_query_completions(self, view, prefix, _locations):
57+
QUOTES = ("\"", "'")
58+
59+
loc = _locations[0]
60+
prevCh = view.substr(loc - len(prefix) - 1)
61+
nextCh = view.substr(loc)
62+
prevQuote = prevCh in QUOTES and prevCh
63+
nextQuote = nextCh in QUOTES and nextCh == prevQuote and nextCh
64+
65+
def postfix(c):
66+
(display, word) = c
67+
if prevQuote and c[1][0:1] in QUOTES:
68+
word = word[1:]
69+
display = display[1:]
70+
if nextQuote and c[1][-1] in QUOTES:
71+
word = word[0:-1]
72+
display = display.replace("%s%s" % (word, nextQuote), word, 1)
73+
74+
return (display, word)
75+
5776
sel = sel_start(view.sel()[0])
5877
if view.score_selector(sel, 'comment') > 0: return None
5978

@@ -66,6 +85,8 @@ def on_query_completions(self, view, prefix, _locations):
6685
if not fresh:
6786
completions = [c for c in completions if c[1].startswith(prefix)]
6887

88+
completions = [postfix(c) for c in completions]
89+
6990
flags = 0;
7091
if get_setting("tern_inhibit_word_completions", False):
7192
flags |= sublime.INHIBIT_WORD_COMPLETIONS

0 commit comments

Comments
 (0)