Skip to content
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

Fix ctrl-D #1402

Merged
merged 1 commit into from
Mar 23, 2023
Merged

Fix ctrl-D #1402

merged 1 commit into from
Mar 23, 2023

Conversation

acquamarin
Copy link
Collaborator

@acquamarin acquamarin commented Mar 22, 2023

Related to issue #1391
This patch only fixes the bug related to ctr-d an ascii-character. If the character is utf-8, then the bug still exists.

@acquamarin acquamarin requested a review from anuchak March 22, 2023 03:40
uint32_t newPos = nextChar(l);
uint32_t oldPos = getBufCharPos(l);
uint32_t charSize = newPos - oldPos;
memmove(l->buf + oldPos, l->buf + newPos, l->len - oldPos);
l->len -= charSize;
l->chars--;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@anuchak We should have a mechanism to check whether the character to delete is a utf-8 character or not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've changed the name of this variable to totalUTF8Chars and the mechanism is simple, just check if total size of the character > 1.

Also I'm not sure if this variable is even required or not, because I checked DuckDB's codebase and they have no such tracking variable, don't think it is required at all.

@@ -570,6 +570,9 @@ uint32_t linenoiseComputeRenderWidth(const char* buf, size_t len) {
}

int getBufCharPos(struct linenoiseState* l) {
if (l->chars == 0) {
Copy link
Collaborator Author

@acquamarin acquamarin Mar 22, 2023

Choose a reason for hiding this comment

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

@anuchak I don't really understand what this function is doing? Can you add some comments here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This function will most likely not be required, I debugged this function and all it is doing is returning the proper position of the cursor from left.

But l->pos already holds this, that's why in DuckDB's codebase everywhere only l->pos has been used instead of calling a separate function.

I'm currently fixing this issue.

@anuchak
Copy link
Collaborator

anuchak commented Mar 22, 2023

I've pushed some changes and they should fix the original issue that the user has raised:

  • Ctrl + A to go to front of line
  • Crtl + D to delete

So this is working properly now.
Also the getBufCharPos has been removed, the l->pos is enough to track the current position of the cursor, we don't need to calculate that everytime from the starting position.

But we might need to refer to DuckDB because our UTF8 handling still seems to be inadequate.
Our code for handling UTF8 was introduced here: d3dc5d3 and this logic might need to be changed.

@codecov
Copy link

codecov bot commented Mar 22, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.01 ⚠️

Comparison is base (bb2b2a8) 92.80% compared to head (7d211e1) 92.79%.

❗ Current head 7d211e1 differs from pull request most recent head 5629979. Consider uploading reports for the commit 5629979 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1402      +/-   ##
==========================================
- Coverage   92.80%   92.79%   -0.01%     
==========================================
  Files         642      641       -1     
  Lines       22066    22043      -23     
==========================================
- Hits        20478    20455      -23     
  Misses       1588     1588              

see 7 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@acquamarin acquamarin merged commit d69f73e into master Mar 23, 2023
@acquamarin acquamarin deleted the shell-fix branch March 23, 2023 15:26
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.

None yet

3 participants