Skip to content

feature(gutter): add experimental ability to replace fold icon with custom for a specific row #5787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 14, 2025

Conversation

nlujjawal
Copy link
Contributor

@nlujjawal nlujjawal commented Apr 3, 2025

Issue #, if available:

Description of changes:
Adding Experimental capability in gutter to replace the fold icon with the custom icon.
Custom widget Icon can be added which will hides the fold Icon and show custom widget icon.
And custom widget Icon can be removed which will remove the custom widget and displays the fold icon.

@nlujjawal nlujjawal force-pushed the gutter_icon branch 2 times, most recently from dccd10f to 0dc96b2 Compare April 3, 2025 08:40
Copy link

codecov bot commented Apr 3, 2025

Codecov Report

Attention: Patch coverage is 94.68085% with 10 lines in your changes missing coverage. Please review.

Project coverage is 87.32%. Comparing base (78ad9c7) to head (efc5688).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/edit_session.js 14.28% 6 Missing ⚠️
src/layer/gutter.js 96.07% 2 Missing ⚠️
src/layer/gutter_test.js 98.46% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5787      +/-   ##
==========================================
+ Coverage   87.24%   87.32%   +0.07%     
==========================================
  Files         604      605       +1     
  Lines       44305    44527     +222     
  Branches     7265     7287      +22     
==========================================
+ Hits        38656    38881     +225     
+ Misses       5649     5646       -3     
Flag Coverage Δ
unittests 87.32% <94.68%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@akoreman
Copy link
Contributor

akoreman commented Apr 3, 2025

We can do this in a follow-up PR, but we should also make sure these custom widgets can get triggered by users using the keyboard gutter handler.

Comment on lines 601 to 625
hideFoldWidget(row) {
const cells = this.$lines.cells;
const cell = cells[row];
if (cell && cell.element) {
const foldWidget = cell.element.childNodes[1];
if (foldWidget) {
dom.setStyle(foldWidget.style, "display", "none");
}
}
}

/**
* Shows the fold widget/icon from a specific row in the gutter
* @param {number} row The row number from which to show the fold icon
*/
showFoldWidget(row) {
const cells = this.$lines.cells;
const cell = cells[row];
if (cell && cell.element) {
const foldWidget = cell.element.childNodes[1];
if (foldWidget) {
dom.setStyle(foldWidget.style, "display", "inline-block");
}
}
}
Copy link
Contributor

@xyos xyos Apr 4, 2025

Choose a reason for hiding this comment

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

should these 2 be a toggleFoldWidget(row, show)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will lead a lot of if else and can lead to less readability

Copy link
Contributor

Choose a reason for hiding this comment

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

only lines 607 and 622 are uncommon and it would be a simple ternary, do you still think it would be less readable?

Copy link
Contributor

Choose a reason for hiding this comment

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

if we merge them, I would maybe call it something like toggleFoldWidgetVisibility to make sure it's clear we are toggling the visibility of the widget and are not folding/unfolding the code at that widget.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is 2 lines(one is if condition) of difference now in both the functions and if we add toggle logic,
There will be 2 extra nested if's with two more of the if's which will always exists which I think won't be that much readable.

@akoreman akoreman self-requested a review April 7, 2025 08:29
$getGutterCell(row){
// contains only visible rows
const cells = this.$lines.cells;
const visibileRow= this.session.documentToScreenRow(row,0);
Copy link
Member

Choose a reason for hiding this comment

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

documentToScreenRow on large documents can be much slower than searching row in the cells array

Copy link
Contributor Author

@nlujjawal nlujjawal Apr 11, 2025

Choose a reason for hiding this comment

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

Searching the cells doesn't work properly in case when the line is folded and you move the cursor to the right of the fold symbol in the code. It doesn't work because at that time cursor is on a hidden row.

I tried creating a large document of 50K lines and 100 custom widgets at a time, current code seems to be working fine without any lag.

@nlujjawal nlujjawal changed the title feature(gutter): add ability to replace fold icon with custom for a specific row feature(gutter): add experimental ability to replace fold icon with custom for a specific row Apr 14, 2025
Copy link
Member

@nightwing nightwing left a comment

Choose a reason for hiding this comment

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

i am not convinced that this is a good api addition, but approving as experimental

@nlujjawal
Copy link
Contributor Author

i am not convinced that this is a good api addition, but approving as experimental

Do you see any concern with the code or its the feature you dont like?

@nlujjawal nlujjawal merged commit 6fde745 into master Apr 14, 2025
3 checks passed
@nlujjawal nlujjawal deleted the gutter_icon branch April 14, 2025 12:44
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.

4 participants