Repository: spyder-ide/spyder

Issue:
The extra selection is not sometimes displayed.
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

I am using spyder-vim. Spyder-vim uses an extra_selection of the editor to display a selection of vim.
But spyder-ide does not sometimes display the extra_selection.

![Err](https://user-images.githubusercontent.com/22970578/99889612-358dc000-2c9a-11eb-8245-69e39ebcf022.gif)



The problem seems to occur in the following code.

https://github.com/spyder-ide/spyder/blob/9bec75b8536164073137e4ec8d75870657d120fa/spyder/plugins/editor/utils/decoration.py#L118-L126

I think selectionStart and selectionEnd of cursor should be considered.

Thank you for reading my issue.



## Versions

* Spyder version: 4.3.0.dev0 4e0e212bc
* Python version: 3.8.5
* Qt version: 5.12.5
* PyQt5 version: 5.12.3
* Operating System: Linux 5.4.0-54-generic

### Dependencies

```

# Mandatory:
atomicwrites >=1.2.0            :  1.4.0 (OK)
chardet >=2.0.0                 :  3.0.4 (OK)
cloudpickle >=0.5.0             :  1.6.0 (OK)
diff_match_patch >=20181111     :  20200713 (OK)
intervaltree >=3.0.2            :  3.1.0 (OK)
IPython >=4.0                   :  7.19.0 (OK)
jedi =0.17.2                    :  0.17.2 (OK)
jsonschema >=3.2.0              :  3.2.0 (OK)
keyring >=17.0.0                :  21.4.0 (OK)
nbconvert >=4.0                 :  6.0.7 (OK)
numpydoc >=0.6.0                :  1.1.0 (OK)
parso =0.7.0                    :  0.7.0 (OK)
pexpect >=4.4.0                 :  4.8.0 (OK)
pickleshare >=0.4               :  0.7.5 (OK)
psutil >=5.3                    :  5.7.2 (OK)
pygments >=2.0                  :  2.7.2 (OK)
pylint >=1.0                    :  2.6.0 (OK)
pyls >=0.36.1;<1.0.0            :  v4.1.4+950.g4e0e212bc (OK)
pyls_black >=0.4.6              :  0.4.6 (OK)
pyls_spyder >=0.1.1             :  0.1.1 (OK)
qdarkstyle >=2.8                :  2.8.1 (OK)
qtawesome >=0.5.7               :  1.0.1 (OK)
qtconsole >=4.7.7               :  4.7.7 (OK)
qtpy >=1.5.0                    :  1.9.0 (OK)
rtree >=0.8.3                   :  0.9.4 (OK)
setuptools >=39.0.0             :  50.3.1.post20201107 (OK)
sphinx >=0.6.6                  :  3.2.1 (OK)
spyder_kernels >=1.10.0;<1.11.0 :  1.11.0.dev0 (OK)
three_merge >=0.1.1             :  0.1.1 (OK)
watchdog >=0.10.3               :  0.10.3 (OK)
xdg >=0.26                      :  0.27 (OK)
zmq >=17                        :  19.0.2 (OK)

# Optional:
cython >=0.21                   :  0.29.21 (OK)
matplotlib >=2.0.0              :  3.3.2 (OK)
numpy >=1.7                     :  1.19.2 (OK)
pandas >=1.1.1                  :  1.1.3 (OK)
scipy >=0.17.0                  :  1.5.2 (OK)
sympy >=0.7.3                   :  1.6.2 (OK)

# Spyder plugins:
spyder_vim                      :  0.1.0.dev0 (OK)
```



Discussion:
Hey @ok97465, thanks for reporting. Since it seems you have an idea on how to solve this problem, would you like to submit a pull request for that?

That way it'd be easier to understand how we could solve this issue.

Resolving patch:
diff --git a/spyder/plugins/editor/utils/decoration.py b/spyder/plugins/editor/utils/decoration.py
--- a/spyder/plugins/editor/utils/decoration.py
+++ b/spyder/plugins/editor/utils/decoration.py
@@ -120,8 +120,19 @@ def _update(self):
             # Update visible decorations
             visible_decorations = []
             for decoration in self._decorations:
+                need_update_sel = False
+                cursor = decoration.cursor
+                sel_start = cursor.selectionStart()
+                # This is required to update extra selections from the point
+                # an initial selection was made.
+                # Fixes spyder-ide/spyder#14282
+                if sel_start is not None:
+                    doc = cursor.document()
+                    block_nb_start = doc.findBlock(sel_start).blockNumber()
+                    need_update_sel = first <= block_nb_start <= last
+
                 block_nb = decoration.cursor.block().blockNumber()
-                if (first <= block_nb <= last or
+                if (first <= block_nb <= last or need_update_sel or
                         decoration.kind == 'current_cell'):
                     visible_decorations.append(decoration)
                     try:


Test patch: