mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Allow smarts to override the tab stop width in the editor
This commit is contained in:
parent
719a83584f
commit
8e287bfac2
@ -8,6 +8,8 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
class NullSmarts(object):
|
class NullSmarts(object):
|
||||||
|
|
||||||
|
override_tab_stop_width = None
|
||||||
|
|
||||||
def __init__(self, editor):
|
def __init__(self, editor):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ def get_leading_whitespace_on_line(editor, previous=False):
|
|||||||
|
|
||||||
class Smarts(NullSmarts):
|
class Smarts(NullSmarts):
|
||||||
|
|
||||||
|
override_tab_stop_width = 4
|
||||||
|
|
||||||
def handle_key_press(self, ev, editor):
|
def handle_key_press(self, ev, editor):
|
||||||
key = ev.key()
|
key = ev.key()
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ class TextEdit(PlainTextEdit):
|
|||||||
self.apply_theme(theme)
|
self.apply_theme(theme)
|
||||||
w = self.fontMetrics()
|
w = self.fontMetrics()
|
||||||
self.space_width = w.width(' ')
|
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)
|
self.setTabStopWidth(tw * self.space_width)
|
||||||
if dictionaries_changed:
|
if dictionaries_changed:
|
||||||
self.highlighter.rehighlight()
|
self.highlighter.rehighlight()
|
||||||
@ -220,12 +220,12 @@ class TextEdit(PlainTextEdit):
|
|||||||
sclass = get_smarts(syntax)
|
sclass = get_smarts(syntax)
|
||||||
if sclass is not None:
|
if sclass is not None:
|
||||||
self.smarts = sclass(self)
|
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)))
|
self.setPlainText(unicodedata.normalize('NFC', unicode(text)))
|
||||||
if process_template and QPlainTextEdit.find(self, '%CURSOR%'):
|
if process_template and QPlainTextEdit.find(self, '%CURSOR%'):
|
||||||
c = self.textCursor()
|
c = self.textCursor()
|
||||||
c.insertText('')
|
c.insertText('')
|
||||||
if syntax == 'python':
|
|
||||||
self.setTabStopWidth(4 * self.space_width)
|
|
||||||
|
|
||||||
def change_document_name(self, newname):
|
def change_document_name(self, newname):
|
||||||
self.highlighter.doc_name = newname
|
self.highlighter.doc_name = newname
|
||||||
|
Loading…
x
Reference in New Issue
Block a user