The function of shielding the text to be selected automatically when the mouse is right-clicked

if you right-click on an element, it will be selected if there is text near the text.
now I want to remove this default function
. There are two
1 css user-select:none;
2 js window.getSelection (). RemoveAllRanges ();
methods that have been tried. Both methods have a problem: they will clear out the text that was manually selected before

.

Boss, thank you very much for giving me some ideas that have done similar functions.

Mar.22,2021

even if you don't write anything, by default. The user's right click will also clear the previously manually selected text


document.addEventListener('mousedown', (event) => {
      // 
      if (event.button === 2) {
        // 
        if (window.getSelection().isCollapsed) {
          // 
          document.body.style.userSelect = 'none';

          // 
          setTimeout(() => {
            document.body.style.userSelect = 'auto';
          }, 0);
        }
      }
    });
Menu