Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions spec/workspace-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,41 @@ describe('Workspace', () => {
expect(
workspace.getActiveTextEditor().getCursorBufferPosition()
).toEqual([2, 11])

await workspace.open('a', { initialLine: null, initialColumn: 4 });

expect(
workspace.getActiveTextEditor().getCursorBufferPosition()
).toEqual([0, 4])

await workspace.open('a', { initialLine: 2, initialColumn: null });

expect(
workspace.getActiveTextEditor().getCursorBufferPosition()
).toEqual([2, 0])
});

it('does not throw when opened without position options', async () => {
await workspace.open('a', {});
await workspace.open('a', { initialLine: null, initialColumn: null });
await workspace.open('a', {
initialLine: undefined,
initialColumn: undefined
});
});

it('does not throw when opening a file outside the project with null position options', async () => {
// atom-application.js parsePathToOpen() sets initialLine/initialColumn to null
// for files opened without a line:column suffix (e.g. via recent files or drag-and-drop)
const dir = temp.mkdirSync('outside-project');
const filePath = path.join(dir, 'outside.txt');
fs.writeFileSync(filePath, 'content outside project\n');

await workspace.open(filePath, { initialLine: null, initialColumn: null });

expect(
workspace.getActiveTextEditor().getCursorBufferPosition()
).toEqual([0, 0]);
});

it('unfolds the fold containing the line', async () => {
Expand Down
15 changes: 6 additions & 9 deletions src/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,15 +1264,12 @@ module.exports = class Workspace extends Model {
pane.activate();
}

let initialColumn = 0;
let initialLine = 0;
if (!Number.isNaN(options.initialLine)) {
initialLine = options.initialLine;
}
if (!Number.isNaN(options.initialColumn)) {
initialColumn = options.initialColumn;
}
if (initialLine >= 0 || initialColumn >= 0) {
const hasInitialLine = typeof options.initialLine === 'number' && !Number.isNaN(options.initialLine) && options.initialLine >= 0;
const hasInitialColumn = typeof options.initialColumn === 'number' && !Number.isNaN(options.initialColumn) && options.initialColumn >= 0;
const initialLine = hasInitialLine ? options.initialLine : 0;
const initialColumn = hasInitialColumn ? options.initialColumn : 0;

if (hasInitialLine || hasInitialColumn) {
if (typeof item.setCursorBufferPosition === 'function') {
item.setCursorBufferPosition([initialLine, initialColumn]);
}
Expand Down
Loading