Skip to content

Conversation

@ahdzib-maya
Copy link
Contributor

Problem

The get_scol() function returns byte-based column (treesitter offset + 1) while lines.get_start_col() returns visual column with tab expansion.

This mismatch causes sibling navigation (Up/Down) to fail when files use tabs for indentation. The column comparison in get_neighbor_at_same_col() requires exact match (candidate_col == scol), but:

  • get_scol() returns byte column (e.g., 3 for \t\tvar)
  • get_start_col() returns visual column (e.g., 9 with tabstop=4)

So siblings at the same indentation are rejected because 9 == 3 is false.

Interestingly, get_down_and_in() (Right movement) uses candidate_col > scol, which accidentally passes (9 > 3), making Right work for sibling navigation while Down doesn't.

Solution

Change get_scol() to return the visual column using lines.get_start_col(), making it consistent with how candidate columns are calculated.

Testing

Tested with Go files using tabs for indentation. Before the fix, j/k (Down/Up) couldn't navigate between sibling statements inside a block. After the fix, sibling navigation works correctly.

@aaronik
Copy link
Owner

aaronik commented Dec 4, 2025

Great PR, thank you! Gotta get the tests passing before it can be merged though.

@ahdzib-maya ahdzib-maya force-pushed the fix/visual-column-calculation branch 2 times, most recently from 3551c52 to fea46c1 Compare December 4, 2025 23:11
@ahdzib-maya
Copy link
Contributor Author

Great PR, thank you! Gotta get the tests passing before it can be merged though.

Ready to merge @aaronik

@aaronik
Copy link
Owner

aaronik commented Dec 7, 2025

Excellent - is there any way you can add a test that covers this? It should be relatively easy, just adding a go fixture file that covers this behavior? Otherwise at some point this fix is going to revert and the issue is going to come back

@ahdzib-maya ahdzib-maya marked this pull request as draft December 9, 2025 21:14
The navigation functions compare columns using lines.get_start_col() which
returns visual column (with tab expansion). The current() function in
targets.lua was returning byte column from nodes.get_scol(), causing
sibling detection to fail when files use tabs for indentation.

This fix changes current() to use visual column for the comparison,
using the node's starting row (not cursor row) to handle cases where
cursor is inside a multi-line node that starts on a different line.

Fixes sibling navigation (Up/Down) in files with tab indentation.
Tests the visual column fix by using Go files (which use tabs
by convention). Validates that move_down/move_up correctly
navigate between sibling nodes at the same indentation level
when the file uses tab characters.

Test cases:
- var declarations as siblings
- if blocks as siblings
- top-level function declarations
@ahdzib-maya ahdzib-maya force-pushed the fix/visual-column-calculation branch from c7d6751 to 7ed3794 Compare December 9, 2025 23:57
@ahdzib-maya ahdzib-maya marked this pull request as ready for review December 10, 2025 00:02
@aaronik aaronik merged commit c1028cb into aaronik:main Dec 10, 2025
1 check passed
@aaronik
Copy link
Owner

aaronik commented Dec 10, 2025

Fantastic, thanks for the PR @ahdzib-maya!

@ahdzib-maya ahdzib-maya deleted the fix/visual-column-calculation branch December 10, 2025 18:49
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