Skip to content

Commit

Permalink
Merge from 3.x: PR #3864
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Dec 20, 2016
2 parents 1477adc + bc1220c commit 57696d5
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions spyder/widgets/sourcecode/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import re
import sys
from collections import OrderedDict

# Third party imports
from qtpy.compat import to_qvariant
Expand Down Expand Up @@ -229,7 +230,7 @@ def __init__(self, parent=None):
BaseEditMixin.__init__(self)
self.setAttribute(Qt.WA_DeleteOnClose)

self.extra_selections_dict = {}
self.extra_selections_dict = OrderedDict()

self.textChanged.connect(self.changed)
self.cursorPositionChanged.connect(self.cursor_position_changed)
Expand Down Expand Up @@ -305,28 +306,40 @@ def set_palette(self, background, foreground):


#------Extra selections
def extra_selection_length(self, key):
selection = self.get_extra_selections(key)
if selection:
cursor = self.extra_selections_dict[key][0].cursor
selection_length = cursor.selectionEnd() - cursor.selectionStart()
return selection_length
else:
return 0

def get_extra_selections(self, key):
return self.extra_selections_dict.get(key, [])

def set_extra_selections(self, key, extra_selections):
self.extra_selections_dict[key] = extra_selections

self.extra_selections_dict = \
OrderedDict(sorted(self.extra_selections_dict.items(),
key=lambda s: self.extra_selection_length(s[0]),
reverse=True))

def update_extra_selections(self):
extra_selections = []
for key, extra in list(self.extra_selections_dict.items()):
if key == 'current_line' or key == 'current_cell':
# Python 3 compatibility (weird): current line has to be
# Python 3 compatibility (weird): current line has to be
# highlighted first
extra_selections = extra + extra_selections
else:
extra_selections += extra
self.setExtraSelections(extra_selections)

def clear_extra_selections(self, key):
self.extra_selections_dict[key] = []
self.update_extra_selections()



def changed(self):
"""Emit changed signal"""
self.modificationChanged.emit(self.document().isModified())
Expand Down

0 comments on commit 57696d5

Please sign in to comment.