ProgerXP / Notepad2e

Word highlighting, simultaneous editing, split views, math evaluation, un/grep, comment reformatting, UAC elevation, complete regexps (PCRE), Lua lexers, DPI awareness and more (XP+)
Other
375 stars 52 forks source link

Sort: use rectangular selection for merging lines #336

Closed ProgerXP closed 3 years ago

ProgerXP commented 3 years ago

Sort Lines (Alt+O) has 3 options to work with duplicate lines. However, they are using whole line even if Column sort is enabled - this should be changed.

a a
b a

Select the 2nd column and Sort using Merge lines. Notepad2 keeps both lines while after this change only the first line should be kept.

Also rename the Column sort checkbox to Column sort and merge (rectangular selection)

ProgerXP commented 3 years ago

WIP, findings so far:

ProgerXP commented 3 years ago

We have finished this and cleaned up the function along the way, removed redundant conditions and made the code less tangled (it's still pretty tangled though).

* Notepad2 has 4 callback functions (for `qsort()`); to implement this, we'd need to either edit them, add 4 more functions or merge all of them into one callback and do checks for Sort modes inside it instead of outside (less code but possibly slower)

We have replaced it with a single callback. There should be no performance penalty because it invokes one of standard sort functions (strncmp, etc.) using a pointer set up before qsort().

However, column mode (when column doesn't end on line break) + logical number comparison is slower than other modes because it's using WinAPI's StrCmpLogicalW() but there is no "n" version (strcmp / strncmp) and we have to copy string parts to be compared into temporary buffers.

  * line numbers are compared for ascending and descending sort modes (same order; descending doesn't cause later lines to be put first)

Line numbers are affected by asc/desc mode after all, it seems more logical.


@cshnik Let's make a final optimization: when using StrCmpLogicalW(), don't use buffers if user has selected column that ends on line end. This is because if original compared strings end on \0 we don't have to copy them, we just pass the pointer to first compared character.

cshnik commented 3 years ago

Let's make a final optimization: when using StrCmpLogicalW(), don't use buffers if user has selected column that ends on line end. This is because if original compared strings end on \0 we don't have to copy them, we just pass the pointer to first compared character.

Done.