bobbylight / AutoComplete

A code completion library for Swing text components, with special support for RSyntaxTextArea.
BSD 3-Clause "New" or "Revised" License
166 stars 55 forks source link

Completion list "dirty" before you type something to trigger autocompletion. #70

Closed hshafie closed 2 years ago

hshafie commented 4 years ago

Hello,

The issue is best described using an example:

I use rsyntaxtextarea-3.0.8 and autocomplete-3.0.5 to edit an XHTML file. I have implemented my own XMLCompletionProvider extending CompletionProviderBase.

I use this facility to set the align attribute of to "left". It works fine. The completion list contains "center", "char", "justify", "left", "right", just as expected.

Now I want to add a new attribute: valign. Pressing Ctrl-SPACE displays a list still containing "center", "char", "justify", "left", "right" with "left" being selected (see screenshot Stock_autocomplete-3.0.5_list_dirty.png) until I start typing "v" to trigger the autocompletion.

This happens for me on my Linux box, whether using latest Java 8 or latest Java 13, whether using the Metal LAF or another LAF (FlatLAF). I can also test this on Windows and on the Mac if this helps you.

I made this patch and it seems to be at least a workaround for this issue.

/usr/local/src/rsta3.0.8/autocomplete-3.0.5-sources/org/fife/ui/autocomplete$ diff -u AutoCompletePopupWindow.java.ORI  AutoCompletePopupWindow.java
--- AutoCompletePopupWindow.java.ORI    2020-01-18 11:11:40.000000000 +0100
+++ AutoCompletePopupWindow.java        2020-03-02 16:57:12.852601488 +0100
@@ -762,7 +762,15 @@
                        if (!visible) { // Do after super.setVisible(false)
                                lastSelection = list.getSelectedValue();
                                model.clear();
-                       }
+                       } else {
+                            // XMLmind patch: without this repaint, before
+                            // typing anything and thus triggering the
+                            // autocompletion, the list is still "dirty" and
+                            // contains the items corresponding to last
+                            // autocompletion.
+                            
+                            list.repaint();
+                        }

                        // Must set descWindow's visibility one way or the other each time,
                        // because of the way child JWindows' visibility is handled - in

Using my patched autocomplete.jar, after setting the value of attribute align to "left", pressing Ctrl-SPACE displays a list containing attribute names as expected: abbr, axis, char, etc. See screenshot Modified_autocomplete-3.0.5_list_up_to_date.png.

Thanks.

hshafie commented 4 years ago

This bug is still present in autocomplete v3.1.0.

bobbylight commented 2 years ago

Better late than never! Thanks for the fix.

hshafie commented 2 years ago

Thank you so much for this bug fix and of course also, for your excellent software component. Can't do without it!