-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Improve positioning when opening file at line #19272
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1065,6 +1065,12 @@ module.exports = class Workspace extends Model { | |
if (typeof item.setCursorBufferPosition === 'function') { | ||
item.setCursorBufferPosition([initialLine, initialColumn]) | ||
} | ||
if (typeof item.unfoldBufferRow === 'function') { | ||
item.unfoldBufferRow(initialLine) | ||
} | ||
if (typeof item.scrollToBufferPosition === 'function') { | ||
item.scrollToBufferPosition([initialLine, initialColumn], { center: true }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've included a test to verify the unfolding behavior, but I have not included a test for scrolling the line to the center of the editor. After looking into what it would take to add a test for scrolling the line to the center of the editor, it seems like it the effort required to add and maintain that test probably isn't worth the rather minor benefit that we'd get from such a test. I think we'd have to set the window to a certain size and then check the coordinates of the line in the viewport. I think it's do-able, but the benefit doesn't feel like it's worth the effort. If anyone feels differently and has thoughts on how to best test this change, please let me know. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, specially since we already have a test in the text editor that actually checks that when passing the |
||
} | ||
} | ||
|
||
const index = pane.getActiveItemIndex() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conditional and the one above are inspired by this pre-existing conditional:
atom/src/workspace.js
Lines 1065 to 1067 in 0c51771
That conditional ☝️ was added in 11112cb to support the scenario "where a custom editor is opened that isn't a text editor" so that "it won't blow up if the custom editor doesn't implement
setCursorBufferPosition
."That same motivation seems relevant to the calls to
unfoldBufferRow
andscrollToBufferPosition
introduced in this pull request, so I've followed the same pattern.