diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-06-08 05:50:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-08 05:50:36 (GMT) |
commit | a4868473e7a0487bd882531490ff8856b952f9b3 (patch) | |
tree | bd8e09b312582964b473fb45e638aae687b78202 /Lib/idlelib/codecontext.py | |
parent | 43202e05c24907576ffd2b10762b18225be7f278 (diff) | |
download | cpython-a4868473e7a0487bd882531490ff8856b952f9b3.zip cpython-a4868473e7a0487bd882531490ff8856b952f9b3.tar.gz cpython-a4868473e7a0487bd882531490ff8856b952f9b3.tar.bz2 |
bpo-33768: IDLE: Clicking on code context line moves it to top of editor (GH-7411)
(cherry picked from commit 041272b657867f5bec925b19aabf23944125d49b)
Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
Diffstat (limited to 'Lib/idlelib/codecontext.py')
-rw-r--r-- | Lib/idlelib/codecontext.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/idlelib/codecontext.py b/Lib/idlelib/codecontext.py index 73d3ba6..8b378bc 100644 --- a/Lib/idlelib/codecontext.py +++ b/Lib/idlelib/codecontext.py @@ -117,6 +117,7 @@ class CodeContext: height=1, width=1, # Don't request more than we get. padx=padx, border=border, relief=SUNKEN, state='disabled') + self.context.bind('<ButtonRelease-1>', self.jumptoline) # Pack the context widget before and above the text_frame widget, # thus ensuring that it will appear directly above text_frame. self.context.pack(side=TOP, fill=X, expand=False, @@ -196,6 +197,20 @@ class CodeContext: self.context.insert('end', '\n'.join(context_strings[showfirst:])) self.context['state'] = 'disabled' + def jumptoline(self, event=None): + "Show clicked context line at top of editor." + lines = len(self.info) + if lines == 1: # No context lines are showing. + newtop = 1 + else: + # Line number clicked. + contextline = int(float(self.context.index('insert'))) + # Lines not displayed due to maxlines. + offset = max(1, lines - self.context_depth) - 1 + newtop = self.info[offset + contextline][0] + self.text.yview(f'{newtop}.0') + self.update_code_context() + def timer_event(self): "Event on editor text widget triggered every UPDATEINTERVAL ms." if self.context: |