Repository: spyder-ide/spyder

Issue:
Highlight instances not shown when scrolling
[Demo vs 4.1.5](https://puu.sh/GP9Hq/9414fe2be8.mp4)


Discussion:
That's per design: from 4.2.0 onwards we'll only highlight occurrences in the visible portion of the file to avoid delays in the editor when trying to highlight a potentially very high number.

If you have a better idea on how to fix that and are willing to invest time to do it, we're welcome to hear it. Otherwise, please feel free to close this issue.
@ccordoba12 I see. Couldn't one of following be done instead?:

  1. Highlight within plusminus X lines of current view
  2. Highlight _up to_ Y occurrences outside of current view

This way most usage of local scrolling is accounted for without having to hit all matches.
Thanks for the suggestions. Point 1 is already implemented and 2 would require resources we didn't plan for in the next months.

Besides, the scrollflag on the right (next to the vertical scrollbar) signals where all occurrences are, so you can jump anywhere to the file and wait a little bit for them to appear. And it works the same for all other kinds of highlights in the editor.

So it's up to you if want to see this implemented before the next six months. 
@ccordoba12 Hmm, you're right, there's a little bit of 1. This is fairly bothersome as I relied much on this highlighting, but sidebar preserving instances does help - guess can adapt to it. Dropping the `!` for `pdb` is the biggest plus for me in 4.2.0.

One more idea - 3: keep usual highlighting unless number of lines exceed Z (just like for code folding).
Ok, that's a good idea. We'll see what we can do to improve this in 4.2.2.
On my computer (Windows 10 and Python 38-32) after scroll, the occurencies doesn't highlight even if I wait long time.
They appear only for a brief moment when I click inside the code window.
But suddenly the highlight point is changed and so are changed the little purple indicators in the sidebar.

I have the same problem as @Archi712 (Spyder 4.2.3, Windows 10). When I scroll the highlights never (never) happen past a few lines beyond the view. 

![highlights](https://user-images.githubusercontent.com/39873368/111391626-1fa08100-8709-11eb-9776-be848f7c9f13.jpg)

You never realise how much you rely on some great features, until you lose them. I find myself now squinting through the code trying to find something that was so easy to find before. Great work anyway :-)
@lagunabravo, you need to stop and wait for a bit (less than a second) to see the occurrences painted in the screen. If you scroll constantly, they won't be updated.

We had to do that to avoid serious performance issues while trying to paint hundreds of occurrences in very long documents.
Thank you for your prompt reply @ccordoba12 
I may have some setting wrong but, if I select something the occurrences show up in the sidebar after a short time. If I then scroll, only a few lines past the initial view the occurrences stop being highlighted (as per screenshot before). No matter how long I wait, or if I scroll fast or slow. Any suggestions?
Yesterday I installed spyder 4.2.3 and have the same problem.

It doesn’t matter how much time I wait, highlighting never happen.
Highlighting appear only for a brief moment when I click inside the window.

If could be of any help, I could add that I don’t scroll the page with arrow buttons, but I click directly in the vertical bar where I see blue dashes.

Best regards.
Riccado.

Da: lagunabravo ***@***.***>
Inviato: mercoledì 17 marzo 2021 05:19
A: spyder-ide/spyder ***@***.***>
Cc: Carassale Riccardo ***@***.***>; Mention ***@***.***>
Oggetto: [EXTERNAL] Re: [spyder-ide/spyder] Highlight instances delayed when scrolling (#14268)


Thank you for your prompt reply @ccordoba12<https://urldefense.com/v3/__https:/github.com/ccordoba12__;!!JZsaRFfwqOYHaA!g9Q8_8IEpQAltuMccp3ICBzmC_SK6-pZ5mNDvpnPzGiGB0JDZekPagveef96ZK6Vs7c_21okBpE$>
I may have some setting wrong but, if I select something the occurrences show up in the sidebar after a short time. If I then scroll, only a few lines past the initial view the occurrences stop being highlighted (as per screenshot before). No matter how long I wait, or if I scroll fast or slow. Any suggestions?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://urldefense.com/v3/__https:/github.com/spyder-ide/spyder/issues/14268*issuecomment-800781403__;Iw!!JZsaRFfwqOYHaA!g9Q8_8IEpQAltuMccp3ICBzmC_SK6-pZ5mNDvpnPzGiGB0JDZekPagveef96ZK6Vs7c_510qWZs$>, or unsubscribe<https://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AQAN4LKSSGEYBP3DSJ5I7NDTEAUSNANCNFSM4T3W7FJA__;!!JZsaRFfwqOYHaA!g9Q8_8IEpQAltuMccp3ICBzmC_SK6-pZ5mNDvpnPzGiGB0JDZekPagveef96ZK6Vs7c_JGa6Pls$>.



P
Prima di stampare questa comunicazione consideratene, per favore, l'impatto ambientale
Please consider the environment before printing this email.

________________________________

Questo messaggio e i suoi allegati sono confidenziali e destinati ad essere inviati esclusivamente ai destinatari effettivi per gli scopi e gli usi previsti. Qualsiasi uso, distribuzione, riproduzione o divulgazione da e verso qualsiasi persona diversa dagli utenti previsti é severamente vietata. Se hai ricevuto questo messaggio per errore, ti invitiamo a informare immediatamente il destinatario e ad eliminarlo dal tuo sistema. Ansaldo Energia S.p.A. tratta i dati per ﬁnalità connesse alla richieste formulate e al corretto svolgimento del rapporto in essere. Informazioni dettagliate sono riportate nell'informativa privacy sul sito internet della società, www.ansaldoenergia.com, e potranno essere richieste via e-mail a ***@***.***, a cui poter indirizzare anche eventuali richieste di accesso.

This message and its attachments are conﬁdential intended to be sent exclusively to the actual recipients for the intended purposes and uses. Any use, distribution, reproduction or disclosure to and from any person other than the intended users is strictly prohibited. If you have received this message by mistake, we invite you to notify the recipient immediately and to delete it from your system. Ansaldo Energia S.p.A. processes the data for purposes related to the request formulated and the correct execution of the existing relationship. Detailed information can be found in the privacy policy on company's website, www.ansaldoenergia.com, and can be requested by e-mail to ***@***.*** , to which any access requests may also be addressed.

Hi,
I confirm the bug is also present for me when the option Completion and linting > Linting > **Underline errors and warnings**  is enabled.
Same symptoms: the occurrences are not highlighted until a click is made in the editor window, then quickly disappear after a time equal to Editor > Display > Highlight occurrences after.
Normal behaviour is restored when the option **Underline errors and warnings** is disabled.

Affected from 4.2.* until now 5.0.5
Maybe move to [ux](https://github.com/spyder-ide/ux-improvements/)? @ccordoba12 
I think that's a problem we need to fix here.
Thanks @supercoder-nassim for your comment above! That's what really what led me to find and fix this error.

The fix will be available in our 5.1.2 version, to be released shortly.
@OverLordGoldDragon, your original problem can't really be addressed for performance reasons, sorry.

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/codeeditor.py b/spyder/plugins/editor/widgets/codeeditor.py
--- a/spyder/plugins/editor/widgets/codeeditor.py
+++ b/spyder/plugins/editor/widgets/codeeditor.py
@@ -1300,6 +1300,9 @@ def _process_code_analysis(self, underline):
                     data.selection_start = start
                     data.selection_end = end
 
+                    # Don't call highlight_selection with `update=True` so that
+                    # all underline selections are updated in bulk in
+                    # finish_code_analysis or update_decorations.
                     self.highlight_selection('code_analysis_underline',
                                              data._selection(),
                                              underline_color=block.color)
@@ -2993,8 +2996,11 @@ def update_decorations(self):
 
             self.underline_errors()
             self.update_extra_selections()
-        else:
-            self.decorations.update()
+
+        # This is required to update decorations whether there are or not
+        # underline errors in the visible portion of the screen.
+        # See spyder-ide/spyder#14268.
+        self.decorations.update()
 
     def show_code_analysis_results(self, line_number, block_data):
         """Show warning/error messages."""


Test patch: