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

Text cursor not moving to the correct location with ctrl+c -> ctrl+v #1950

Closed
1 task
german77 opened this issue Nov 4, 2024 · 5 comments
Closed
1 task
Labels
bug Something isn't working

Comments

@german77
Copy link

german77 commented Nov 4, 2024

Operating System

Windows

What's the issue you encountered?

Wrong cursor position that cause multiple issues. Seems to happen in just some lines and not the whole document.
bug
bug2

How can the issue be reproduced?

Selecting a line of code then copy paste multiple times. Results in the cursor positioning in the wrong location. Using ctrl+z to revert the changes will keep some of the text on the editor.

Additionally double click on a word will select the previous text block instead of the word you where hovering.

ImHex Version

1.35.4

ImHex Build Type

  • Nightly or built from sources

Installation type

Portable

Additional context?

Reproduced in two computers with windows 10. Pattern script: https://github.com/german77/TheDudeToHuman/blob/master/imhex.pattern

@german77 german77 added the bug Something isn't working label Nov 4, 2024
@paxcut
Copy link
Contributor

paxcut commented Nov 4, 2024

The problem you are having is that you must have copy pasted the code from some editor that uses \t for tabs. ImHex uses spaces for tabs and there is a PR that changes the tabs to spaces automatically for you that is waiting to be merged. In the mean time you can get around this problem by removing all the tabs (you can find them because the cursor jumps 4 spaces in one click) and using spaces instead.

@german77
Copy link
Author

german77 commented Nov 4, 2024

Just noticed it was the tab causing the issues. Do you mind linking the PR. I don't see it on the list.

@paxcut
Copy link
Contributor

paxcut commented Nov 4, 2024

There isn't a PR specifically for converting tabs to spaces. The way I commit changes and create PRs has changed recently. I used to submit many changes into single PRs but now I create separate ones for each separate change set defined by an issue, a feature, improvement, etc... The (incorrect) code that changes Tabs to spaces can be found in PR #1700 but that is an old type of PR so it is set to draft. All the non-draft PRs should (eventually) add up to the draft PRs.

When I wrote the reply to your issue I was certain that the code was added to one of the smaller PRs but now I am not sure and I'm not going to search for it because that's a pita. I know I said that the code that changes tabs to spaces is waiting to be merged, but if it isn't already it will soon be and the code will hopefully also be correct.

Tabs are really evil and using tabs in the text editor causes many problems besides the ones you found. Search replace, syntax coloring, error markings and many more are affected by them because tabs break the line, column coordinate system we use to locate text in the editor. Initially tabs were incorporated to the line,column coordinates but that makes the code a lot more complex than it needs to be if we simply avoid them altogether.

As such, code created within the editor will always be tab free so the only way to introduce tabs is by pasting them into the code. You should avoid doing that and IMHO we should use spaces in all the editors that allow them, but it is understandably difficult to avoid the occasional tab to slip by being invisible as they are, so rest assured that this is an important part of the text editor which will not be overlooked or neglected. In fact, it deserves a PR of its own even if the code exists in another PR already. If you are interested look forward to it!

@german77
Copy link
Author

german77 commented Nov 4, 2024

Thanks for the explanation. I like spaces as well because they are consistent between editors. This case is just as you described. I copied code from another program which happens to use tabs so it wasn't really apparent in imhex until I used notepad++ and saw the tabs.

paxcut added a commit to paxcut/ImHex that referenced this issue Nov 5, 2024
…n libwolv repo. It uses function added there to remove tabs if they exist on the provider. Additionally, any pasted tab will be translated to spaces automatically. This code was tested successfully using the pattern posted in the issue.
@paxcut
Copy link
Contributor

paxcut commented Nov 5, 2024

I finished with the fixes for this issues. I extended and implemented correctly the changes hinted in the draft PR. Fix changes exist in two PRs one to the libwolv repository and the other to PR #1951. I tested the pattern you posted and while it shows both errors without the fixes, they are no longer reproducible when fixes are applied.

WerWolv pushed a commit that referenced this issue Nov 24, 2024
…rl+v (#1951)

This code fixes issue #1950 This PR depends on PR [#27
](WerWolv/libwolv#27) on libwolv repo


### Problem description
See description of the problem on the issue linked above

### Implementation description
The code in the PR uses function added to the libwolv repository to
remove tabs if they exist on the provider. Additionally, any pasted tab
on the pattern editor will be translated to spaces automatically. This
code was tested successfully using the pattern posted in the issue.
@WerWolv WerWolv closed this as completed Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants