Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
041272b6
Commit
041272b6
authored
Jun 08, 2018
by
Cheryl Sabella
Committed by
Terry Jan Reedy
Jun 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-33768: IDLE: Clicking on code context line moves it to top of editor (GH-7411)
parent
4aa30066
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
0 deletions
+50
-0
Lib/idlelib/codecontext.py
Lib/idlelib/codecontext.py
+15
-0
Lib/idlelib/idle_test/test_codecontext.py
Lib/idlelib/idle_test/test_codecontext.py
+34
-0
Misc/NEWS.d/next/IDLE/2018-06-04-19-23-11.bpo-33768.I_2qpV.rst
...NEWS.d/next/IDLE/2018-06-04-19-23-11.bpo-33768.I_2qpV.rst
+1
-0
No files found.
Lib/idlelib/codecontext.py
View file @
041272b6
...
...
@@ -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
:
...
...
Lib/idlelib/idle_test/test_codecontext.py
View file @
041272b6
...
...
@@ -72,6 +72,7 @@ class CodeContextTest(unittest.TestCase):
del
cls
.
root
def
setUp
(
self
):
self
.
text
.
yview
(
0
)
self
.
cc
=
codecontext
.
CodeContext
(
self
.
editor
)
def
tearDown
(
self
):
...
...
@@ -264,6 +265,39 @@ class CodeContextTest(unittest.TestCase):
# context_depth is 1.
eq
(
cc
.
context
.
get
(
'1.0'
,
'end-1c'
),
' def __init__(self, a, b):'
)
def
test_jumptoline
(
self
):
eq
=
self
.
assertEqual
cc
=
self
.
cc
jump
=
cc
.
jumptoline
if
not
cc
.
context
:
cc
.
toggle_code_context_event
()
# Empty context.
cc
.
text
.
yview
(
f'
{
2
}
.0'
)
cc
.
update_code_context
()
eq
(
cc
.
topvisible
,
2
)
cc
.
context
.
mark_set
(
'insert'
,
'1.5'
)
jump
()
eq
(
cc
.
topvisible
,
1
)
# 4 lines of context showing.
cc
.
text
.
yview
(
f'
{
12
}
.0'
)
cc
.
update_code_context
()
eq
(
cc
.
topvisible
,
12
)
cc
.
context
.
mark_set
(
'insert'
,
'3.0'
)
jump
()
eq
(
cc
.
topvisible
,
8
)
# More context lines than limit.
cc
.
context_depth
=
2
cc
.
text
.
yview
(
f'
{
12
}
.0'
)
cc
.
update_code_context
()
eq
(
cc
.
topvisible
,
12
)
cc
.
context
.
mark_set
(
'insert'
,
'1.0'
)
jump
()
eq
(
cc
.
topvisible
,
8
)
@
mock
.
patch
.
object
(
codecontext
.
CodeContext
,
'update_code_context'
)
def
test_timer_event
(
self
,
mock_update
):
# Ensure code context is not active.
...
...
Misc/NEWS.d/next/IDLE/2018-06-04-19-23-11.bpo-33768.I_2qpV.rst
0 → 100644
View file @
041272b6
Clicking on a context line moves that line to the top of the editor window.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment