[kupfer] clipboard: Detect incremental updates of selection



commit 466637b8ff9c5b6f2c6b88e041788a0a1688d41b
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Mar 7 18:34:02 2010 +0100

    clipboard: Detect incremental updates of selection
    
    Some programs (gtk) update the selection clipboard for every character
    in the selection, so we collect selections that we don't want:
    
        T
        Te
        Tex
        Text
    
    We detect if the new selection has a prefix in the previous selection
    and supercede it.

 kupfer/plugin/clipboard.py |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/plugin/clipboard.py b/kupfer/plugin/clipboard.py
index f8057dd..2b8faf7 100644
--- a/kupfer/plugin/clipboard.py
+++ b/kupfer/plugin/clipboard.py
@@ -58,9 +58,15 @@ class ClipboardSource (Source):
 		newtext = clip.wait_for_text()
 		if not (newtext and newtext.strip()):
 			return
+
 		if newtext in self.clipboards:
 			self.clipboards.remove(newtext)
+		# if the previous text is a prefix of the new selection, supercede it
+		if (is_selection and self.clipboards and
+		    newtext.startswith(self.clipboards[-1])):
+			self.clipboards.pop()
 		self.clipboards.append(newtext)
+
 		while len(self.clipboards) > max_len:
 			self.clipboards.popleft()
 		self.mark_for_update()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]