| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 00a240b commit 3dcccd1
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,8 +17,9 @@ when fetching a calltip. | |||
| 17 | 17 | bpo-27115: For 'Go to Line', use a Query entry box subclass with | |
| 18 | 18 | IDLE standard behavior and improved error checking. | |
| 19 | 19 | ||
| 20 | - bpo-39885: Since clicking to get an IDLE context menu moves the | ||
| 21 | - cursor, any text selection should be and now is cleared. | ||
| 20 | + bpo-39885: When a context menu is invoked by right-clicking outside | ||
| 21 | + of a selection, clear the selection and move the cursor. Cut and | ||
| 22 | + Copy require that the click be within the selection. | ||
| 22 | 23 | ||
| 23 | 24 | bpo-39852: Edit "Go to line" now clears any selection, preventing | |
| 24 | 25 | accidental deletion. It also updates Ln and Col on the status bar. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -499,15 +499,23 @@ def handle_yview(self, event, *args): | |||
| 499 | 499 | rmenu = None | |
| 500 | 500 | ||
| 501 | 501 | def right_menu_event(self, event): | |
| 502 | - self.text.tag_remove("sel", "1.0", "end") | ||
| 503 | - self.text.mark_set("insert", "@%d,%d" % (event.x, event.y)) | ||
| 502 | + text = self.text | ||
| 503 | + newdex = text.index(f'@{event.x},{event.y}') | ||
| 504 | + try: | ||
| 505 | + in_selection = (text.compare('sel.first', '<=', newdex) and | ||
| 506 | + text.compare(newdex, '<=', 'sel.last')) | ||
| 507 | + except TclError: | ||
| 508 | + in_selection = False | ||
| 509 | + if not in_selection: | ||
| 510 | + text.tag_remove("sel", "1.0", "end") | ||
| 511 | + text.mark_set("insert", newdex) | ||
| 504 | 512 | if not self.rmenu: | |
| 505 | 513 | self.make_rmenu() | |
| 506 | 514 | rmenu = self.rmenu | |
| 507 | 515 | self.event = event | |
| 508 | 516 | iswin = sys.platform[:3] == 'win' | |
| 509 | 517 | if iswin: | |
| 510 | - self.text.config(cursor="arrow") | ||
| 518 | + text.config(cursor="arrow") | ||
| 511 | 519 | ||
| 512 | 520 | for item in self.rmenu_specs: | |
| 513 | 521 | try: | |
@@ -520,7 +528,6 @@ def right_menu_event(self, event): | |||
| 520 | 528 | state = getattr(self, verify_state)() | |
| 521 | 529 | rmenu.entryconfigure(label, state=state) | |
| 522 | 530 | ||
| 523 | - | ||
| 524 | 531 | rmenu.tk_popup(event.x_root, event.y_root) | |
| 525 | 532 | if iswin: | |
| 526 | 533 | self.text.config(cursor="ibeam") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | from collections import namedtuple | |
| 6 | 6 | from test.support import requires | |
| 7 | 7 | from tkinter import Tk | |
| 8 | + from idlelib.idle_test.mock_idle import Func | ||
| 8 | 9 | ||
| 9 | 10 | Editor = editor.EditorWindow | |
| 10 | 11 | ||
@@ -92,6 +93,12 @@ def test_tabwidth_8(self): | |||
| 92 | 93 | ) | |
| 93 | 94 | ||
| 94 | 95 | ||
| 96 | + def insert(text, string): | ||
| 97 | + text.delete('1.0', 'end') | ||
| 98 | + text.insert('end', string) | ||
| 99 | + text.update() # Force update for colorizer to finish. | ||
| 100 | + | ||
| 101 | + | ||
| 95 | 102 | class IndentAndNewlineTest(unittest.TestCase): | |
| 96 | 103 | ||
| 97 | 104 | @classmethod | |
@@ -113,13 +120,6 @@ def tearDownClass(cls): | |||
| 113 | 120 | cls.root.destroy() | |
| 114 | 121 | del cls.root | |
| 115 | 122 | ||
| 116 | - def insert(self, text): | ||
| 117 | - t = self.window.text | ||
| 118 | - t.delete('1.0', 'end') | ||
| 119 | - t.insert('end', text) | ||
| 120 | - # Force update for colorizer to finish. | ||
| 121 | - t.update() | ||
| 122 | - | ||
| 123 | 123 | def test_indent_and_newline_event(self): | |
| 124 | 124 | eq = self.assertEqual | |
| 125 | 125 | w = self.window | |
@@ -170,25 +170,51 @@ def test_indent_and_newline_event(self): | |||
| 170 | 170 | w.prompt_last_line = '' | |
| 171 | 171 | for test in tests: | |
| 172 | 172 | with self.subTest(label=test.label): | |
| 173 | - self.insert(test.text) | ||
| 173 | + insert(text, test.text) | ||
| 174 | 174 | text.mark_set('insert', test.mark) | |
| 175 | 175 | nl(event=None) | |
| 176 | 176 | eq(get('1.0', 'end'), test.expected) | |
| 177 | 177 | ||
| 178 | 178 | # Selected text. | |
| 179 | - self.insert(' def f1(self, a, b):\n return a + b') | ||
| 179 | + insert(text, ' def f1(self, a, b):\n return a + b') | ||
| 180 | 180 | text.tag_add('sel', '1.17', '1.end') | |
| 181 | 181 | nl(None) | |
| 182 | 182 | # Deletes selected text before adding new line. | |
| 183 | 183 | eq(get('1.0', 'end'), ' def f1(self, a,\n \n return a + b\n') | |
| 184 | 184 | ||
| 185 | 185 | # Preserves the whitespace in shell prompt. | |
| 186 | 186 | w.prompt_last_line = '>>> ' | |
| 187 | - self.insert('>>> \t\ta =') | ||
| 187 | + insert(text, '>>> \t\ta =') | ||
| 188 | 188 | text.mark_set('insert', '1.5') | |
| 189 | 189 | nl(None) | |
| 190 | 190 | eq(get('1.0', 'end'), '>>> \na =\n') | |
| 191 | 191 | ||
| 192 | 192 | ||
| 193 | + class RMenuTest(unittest.TestCase): | ||
| 194 | + | ||
| 195 | + @classmethod | ||
| 196 | + def setUpClass(cls): | ||
| 197 | + requires('gui') | ||
| 198 | + cls.root = Tk() | ||
| 199 | + cls.root.withdraw() | ||
| 200 | + cls.window = Editor(root=cls.root) | ||
| 201 | + | ||
| 202 | + @classmethod | ||
| 203 | + def tearDownClass(cls): | ||
| 204 | + cls.window._close() | ||
| 205 | + del cls.window | ||
| 206 | + cls.root.update_idletasks() | ||
| 207 | + for id in cls.root.tk.call('after', 'info'): | ||
| 208 | + cls.root.after_cancel(id) | ||
| 209 | + cls.root.destroy() | ||
| 210 | + del cls.root | ||
| 211 | + | ||
| 212 | + class DummyRMenu: | ||
| 213 | + def tk_popup(x, y): pass | ||
| 214 | + | ||
| 215 | + def test_rclick(self): | ||
| 216 | + pass | ||
| 217 | + | ||
| 218 | + | ||
| 193 | 219 | if __name__ == '__main__': | |
| 194 | 220 | unittest.main(verbosity=2) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Make context menu Cut and Copy work again when right-clicking within a | ||
| 2 | + selection. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments