Modify

Opened 19 months ago

Last modified 7 weeks ago

#22423 reopened defect

[Patch] Do not mix capital/lowerkey letter keys in Tags/Memberships window

Reported by: nkamapper Owned by: team
Priority: normal Milestone:
Component: Core Version:
Keywords: sort keys Tags/memberships panel Cc:

Description

In the Tags/Memberships window keys are by default sorted with capital letter keys first, then lowerkey letter keys. If I accidentially hit the column header then the keys are sorted with capital and lowerkey letter keys mixed. I have not found a way to reverse that mistake, except restarting JOSM.

Keys in capital letter are usually temporary keys used when importing, so it is very inconvenient to have them mixed with the "permitted" keys. It increases the risk of forgetting to delete a capital letter key before uploading.

The sorting could be improved by sorting capital letter keys and lowerkey letter keys separately, as per the default sorting, or at least support a way to get back to that state.

Attachments (1)

Capital.osm (322 bytes ) - added by skyper 7 weeks ago.
simple example

Download all attachments as: .zip

Change History (11)

comment:1 by skyper, 19 months ago

+1,
an additional sort option to get back to capital letters on top, would be nice.

comment:2 by nkamapper, 13 months ago

Type: enhancementdefect

It would be very helpful to have this fixed. It is one of the few cases were I often have to exit and restart JOSM.
The simple solution is to always sort capital letter keys first/last, as per the current initial state.

comment:3 by nkamapper, 2 months ago

This is still a pain. Leads to frequent restarts of JOSM.

comment:4 by GerdP, 2 months ago

Cannot reproduce the problem with latest, probably because of changes in r18973, but since unit tests fail this might change again.

comment:5 by taylor.smock, 2 months ago

Even if I do revert r18973, I think this is fixable -- I just have to change Collator.SECONDARY to Collator.TERTIARY. But that may have an effect on other users of AlphanumComparator, so I'll have to do a look-through to see what is affected.

When I originally did the change in r18973, I assumed (wrongly) that String#compareTo and Collator#compare were semantically the same for ASCII characters. I think I can work around that by having an array with mappings. I'm not a fan, but it is a hot path.

EDIT: NVM. It will be a bit more complex; the default sorting rules for the collator are aAbBcC.

Last edited 2 months ago by taylor.smock (previous) (diff)

comment:6 by GerdP, 7 weeks ago

Milestone: 24.02
Resolution: fixed
Status: newclosed

Fixed with r18973 and further changes for tickets #23468 and #23471

by skyper, 7 weeks ago

Attachment: Capital.osm added

simple example

comment:7 by skyper, 7 weeks ago

Keywords: sort keys Tags/memberships panel added
Milestone: 24.02
Resolution: fixed
Status: closedreopened

Does not work for me. Still the same problem on startup the order of the keys is first all keys with a capital letter as first letter and then all keys with a small letter as first letter both "groups" sorted from A-Z resp. a-z. Clicking on "Key" sorts in alphabetical order from bottom to top but with in "group" with each capital letter just above its small equivalent. With another click the latter order is reversed (alphabetical order from bottom to top) with each capital letter just above its small equivalent, again. Further clicking just leads to the last two orders but the sorting with two "groups" (first all capital and then all small letters) is unavailable.

Relative:URL: ^/trunk
Repository:UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
Last:Changed Date: 2024-03-08 13:22:01 +0100 (Fri, 08 Mar 2024)
Revision:19015
Build-Date:2024-03-09 02:30:59
URL:https://josm.openstreetmap.de/svn/trunk

Identification: JOSM/1.5 (19015 en) Linux Debian GNU/Linux 12 (bookworm)
Memory Usage: 279 MB / 1970 MB (85 MB allocated, but free)
Java version: 17.0.10+7-Debian-1deb12u1, Debian, OpenJDK 64-Bit Server VM
Look and Feel: javax.swing.plaf.metal.MetalLookAndFeel
Environment variable LANG: en_US.UTF-8
System property file.encoding: UTF-8
System property sun.jnu.encoding: UTF-8
Locale info: en_US
Numbers with default locale: 1234567890 -> 1234567890
Desktop environment: GNOME

comment:8 by GerdP, 7 weeks ago

OK, seems I didn't understand the wanted behaviour. Now I can reproduce. I'll try to find out where the initial order is created. It seems not to depend on the order in the *.osm file, changing it there has no effect.

comment:9 by GerdP, 7 weeks ago

Hm, the initial order is sorted in a TreeMap (field valueCount in class PropertiesDialog). This sorts the keys using String.compare(), while the dialog sorts them with AlphanumComparator.
I see two possibe fixes:
1) always use String.compare() for the keys (also in the dialog)
2) add a preference to allow a choice which comparator should be used.

The patch for 1) is very simple:

  • src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    C:\josm\core>svn diff   src\org\openstreetmap\josm\gui\dialogs\properties\PropertiesDialog.java
     
    353353        final RemoveHiddenSelection removeHiddenSelection = new RemoveHiddenSelection();
    354354        tagTable.getSelectionModel().addListSelectionListener(removeHiddenSelection);
    355355        tagRowSorter.addRowSorterListener(removeHiddenSelection);
    356         tagRowSorter.setComparator(0, AlphanumComparator.getInstance());
     356        tagRowSorter.setComparator(0, (o1, o2) -> ((String) o1).compareTo((String) o2));
    357357        tagRowSorter.setComparator(1, (o1, o2) -> {
    358358            if (o1 instanceof Map && o2 instanceof Map) {
    359359                final String v1 = ((Map) o1).size() == 1 ? (String) ((Map) o1).keySet().iterator().next() : KeyedItem.DIFFERENT_I18N;

In my eyes this is enough, I see no reason to use the complex sorting for the keys as they are expected to be plain ascii.

comment:10 by GerdP, 7 weeks ago

Summary: Do not mix capital/lowerkey letter keys in Tags/Memberships window[Patch] Do not mix capital/lowerkey letter keys in Tags/Memberships window

Modify Ticket

Change Properties
Set your email in Preferences
Action
as reopened The owner will remain team.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from team to the specified user. Next status will be 'new'.
Next status will be 'needinfo'. The owner will be changed from team to nkamapper.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. The specified ticket will be cross-referenced with this ticket.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.