Allow smarts to override the tab stop width in the editor

This commit is contained in:
Kovid Goyal 2014-11-21 14:45:31 +05:30
parent 719a83584f
commit 8e287bfac2
3 changed files with 7 additions and 3 deletions

View File

@ -8,6 +8,8 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
class NullSmarts(object):
override_tab_stop_width = None
def __init__(self, editor):
pass

View File

@ -35,6 +35,8 @@ def get_leading_whitespace_on_line(editor, previous=False):
class Smarts(NullSmarts):
override_tab_stop_width = 4
def handle_key_press(self, ev, editor):
key = ev.key()

View File

@ -173,7 +173,7 @@ class TextEdit(PlainTextEdit):
self.apply_theme(theme)
w = self.fontMetrics()
self.space_width = w.width(' ')
tw = 4 if self.syntax == 'python' else prefs['editor_tab_stop_width']
tw = self.smarts.override_tab_stop_width if self.smarts.override_tab_stop_width is not None else prefs['editor_tab_stop_width']
self.setTabStopWidth(tw * self.space_width)
if dictionaries_changed:
self.highlighter.rehighlight()
@ -220,12 +220,12 @@ class TextEdit(PlainTextEdit):
sclass = get_smarts(syntax)
if sclass is not None:
self.smarts = sclass(self)
if self.smarts.override_tab_stop_width is not None:
self.setTabStopWidth(self.smarts.override_tab_stop_width * self.space_width)
self.setPlainText(unicodedata.normalize('NFC', unicode(text)))
if process_template and QPlainTextEdit.find(self, '%CURSOR%'):
c = self.textCursor()
c.insertText('')
if syntax == 'python':
self.setTabStopWidth(4 * self.space_width)
def change_document_name(self, newname):
self.highlighter.doc_name = newname