Skip to content

Fix Invalid Point error when opening files without position#1412

Open
asiloisad wants to merge 4 commits into
pulsar-edit:masterfrom
asiloisad:fix_invalid_point
Open

Fix Invalid Point error when opening files without position#1412
asiloisad wants to merge 4 commits into
pulsar-edit:masterfrom
asiloisad:fix_invalid_point

Conversation

@asiloisad

@asiloisad asiloisad commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes TypeError: Invalid Point: (null, null) and Invalid Point: (null, Infinity) errors that occur when opening files without explicit initialLine/initialColumn options.

This commonly happens when opening files outside the current project (e.g., via recent files, drag-and-drop, or external tools).

The Problem

The validation in workspace.open() used !Number.isNaN() to check if position options were provided:

if (!Number.isNaN(options.initialLine)) {
  initialLine = options.initialLine;
}

This is broken because:

  • Number.isNaN(null)false
  • !Number.isNaN(null)true (enters the block)
  • initialLine = null (assigns null)
  • null >= 0true (JavaScript coercion)
  • setCursorBufferPosition([null, null])Error

The Fix

Replace with Number.isFinite() which correctly rejects null, undefined, NaN, and Infinity:

const hasInitialLine = Number.isFinite(options.initialLine) && options.initialLine >= 0;
const hasInitialColumn = Number.isFinite(options.initialColumn) && options.initialColumn >= 0;
const initialLine = hasInitialLine ? options.initialLine : 0;
const initialColumn = hasInitialColumn ? options.initialColumn : 0;

if (hasInitialLine || hasInitialColumn) {
  // position cursor only when explicitly requested
}

This also fixes a secondary issue where the condition initialLine >= 0 || initialColumn >= 0 was always true (since defaults were 0), causing unnecessary cursor positioning on every file open.

@asiloisad

Copy link
Copy Markdown
Contributor Author

The test was failing because Number.isFinite() rejects Infinity, but setCursorBufferPosition can clamp it to the last valid position. Switched to typeof === 'number' && !Number.isNaN() so null/undefined/NaN are still rejected while Infinity passes through for clamping.

@savetheclocktower

Copy link
Copy Markdown
Contributor

Looks good, but same caveat here as with #1536: a new spec would make this easier to land in time for 1.132.0.

(Sorry for not giving you that feedback when you opened this PR three months ago!)

@asiloisad

Copy link
Copy Markdown
Contributor Author

Specs are added 👍.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants