Skip to content

Conversation

lumirlumir
Copy link
Member

@lumirlumir lumirlumir commented Oct 4, 2025

Prerequisites checklist

What is the purpose of this pull request?

This PR originated from #536. While working on that, I found the scope had become too large, so I split this refactoring into a separate PR.

In this PR, I've used the native getLocFromIndex method added in #376 instead of the custom findOffsets util.

Notable changes:

  • Replace the findOffsets util with the native getLocFromIndex.
  • Use ESQuery selectors to reduce code duplication.
  • Move findEmphasisMarkers, checkEmphasis, bufferManager, and other helper functions directly into the ESQuery selector to simplify the code.

What changes did you make? (Give an overview)

In this PR, I've used the native getLocFromIndex method added in #376 instead of the custom findOffsets util.

Related Issues

Ref: #376, #536

Is there anything you'd like reviewers to focus on?

I personally don't prefer large git diffs, but this time there was a lot of room to simplify the logic (resulting in −113 lines of code), so I inevitably produced a large diff.

My main focus while working was reducing unnecessarily nested helper functions and simplifying the line/column <-> offset translation logic.

@eslintbot eslintbot added this to Triage Oct 4, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Oct 4, 2025
@lumirlumir lumirlumir marked this pull request as ready for review October 5, 2025 05:31
@lumirlumir lumirlumir requested review from a team and mdjermanovic October 5, 2025 05:31
@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage Oct 5, 2025
@lumirlumir lumirlumir marked this pull request as draft October 7, 2025 06:58
@lumirlumir lumirlumir marked this pull request as ready for review October 7, 2025 07:01
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mdjermanovic mdjermanovic merged commit d6f2d0f into main Oct 7, 2025
23 checks passed
@mdjermanovic mdjermanovic deleted the refactor-use-getlocfromindex-in-no-space-in-emphasis branch October 7, 2025 09:13
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Oct 7, 2025
* @param {boolean} checkStrikethrough Whether to include strikethrough markers.
* @returns {RegExp} The marker pattern.
*/
function createMarkerPattern(checkStrikethrough) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also remove the function as part of this refactoring as no regular expression is dynamically created?

"paragraph:exit"(node) {
bufferManager.exit(node);
},
":matches(heading, paragraph, tableCell):exit"(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
":matches(heading, paragraph, tableCell):exit"(
"heading, paragraph, tableCell:exit"(

The :matches pseudo-selector is not required.

/** @type {RegExpExecArray | null} */
let match;

while ((match = markerPattern.exec(maskedText)) !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use String#matchAll instead of using while with exec:

Suggested change
while ((match = markerPattern.exec(maskedText)) !== null) {
for (const match of maskedText.matchAll(markerPattern) {

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

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

3 participants