How to deal with exasperating "random text paste" problem in Linux                                     20230616 GLF
-------------------------------------------------------------------------------------------------------------------

All released versions of GLF prepared custom Debian OS build configurations apply the following "fix" by default.
The fix may be reverted by the user if desired with a simple GUI-based configuration change, but the folowing
description of the problem and its consequences should explain why the fix was chosen to be implemented by default.


TEST TO VERIFY EXISTENCE OF PROBLEM

   Set up a text file with many lines of text (thousand or so).
   Make a backup copy of that text file so we can prove it was altered.
   Bring up the original text file in an editor (Pluma, Geany, VSCode, Arduino, it doesn't
      matter).
   Use text "find" function to seach for a small text string KNOWN not to exist in the text.
   
      Example: fudge
       
   You should see that no such instances exist (yet).   

   
THE PROBLEM:   
   
   The problem occurs when the user attempts to view the selected search text in the editor.  This almost always involves using the middle button scroll wheel to locate and position text on the screen. However, users almost always inadvertently press the middle button at beginning or end of rolling the scroll wheel.  In Linux (X), the middle mouse button is not only used to implement a scroll wheel, but also is used by default to paste the contents of the clipboard.  Because of this, the very act of searching for text in the editor ("fudge") often inserts that text into the X clipboard.  If you go randomly somewhere in the text and inadvertently click the middle mouse button, by default it pastes that text at that spot.   Alternately, if you had previously marked text with the mouse in another window, even a command line window, then that previous text is sitting in the X copy-paste buffer and might get pasted into the new text.  
   

ILLUSTRATE THE PROBLEM:   
   
   You have already set up a search for text above ("fudge").  To illustrate the problem, use the middle mouse button to paste that stored text somewhere in the test text file.  Re-verify that it only exists ONCE where you pasted it intentionally.
   
   Now to see the real extent of the problem -- use the middle mouse wheel to scroll rapidly up and down, randomly across many lines of text, repeatedly several times.  This is an action which will happen often in the normal course of editing text, and SHOULD be innocuous.  However, because this rapid use of the scroll wheel involves many rapid starts and stops, one inevitably causes the effect of the "middle click" at random places within the text, polluting the text with repeated pastes of the stored text string.  
   
   Verify the problem by searching the file again for the same text string.  You should see multiple spurious instances at random places.

   THIS IS A BIG PROBLEM.
   

THE FIX:
   
   You can turn OFF the default middle click behavior such that clicking the scroll wheel no longer pastes text.  There are two ways to test this under GLF custom Linux distros (or others based on MATE).  The easy and immediate way to do this (or undo it):  Under System, Preferences, Hardware, Mouse, Mouse Tab -- UNCHECK the item "Enable middlemouse paste", and close the window.  You can immediately test the effect of this change to show it works.  Another, more persistent automatic method to disable middle click paste is explained below (and is recommended for permanent use).
   
   After disabling the middleclick paste as described, if you repeat the above test the problem with random pastes while scrolling SHOULD disappear.  Random rapid scrolling will not produce the spurious side effects.
   
   
WHY YOU SHOULD APPLY THE FIX BY DEFAULT (THIS IS DONE IN CONFIGURATION FOR ALL GLF PREPARED OS BUILDS)
   
   The middle mouse click "paste" function can be quite handy, especially while typing in text in a command shell window.  However the random paste problem while editing text can be DISASTROUS, especially while editing programs -- a previously working program can randomly fail to compile merely by scrolling through the code before the recompile.  And if such random paste corruption occurs during an extended editing session, the user may find it extremely difficult to find and eliminate all the spurious text.  Sometimes the random text happens to land inside a comment and seems to have no effect during compilation, but it still renders internal documentation confusing.  More likely, it will generate random syntax errors which can be fun (NOT) to trace down and fix.  Sometimes the only way to clean up the code is to go back to an earlier version and start over.  This problem is way too important to ignore.  Disabling the middle click "paste" does not prevent other GUI-based cut-and-paste functionality (CTRL-V, CTRL-C), so disabling it need not interfere with normal text editing.
   
   If one NEEDS the middle-click functionality in specific circumstances, one could temporarily re-enable it the same way it was disabled, as long as the user remains aware of the potential for side effects on any open text edit windows. However, this should usually be unnecessary since there is an alternate X "paste" functionality built-in to many applications (including the terminal windows): Shift-Insert.  That sequence allows the SAME paste functionality allowed by the default middle click, without the risk of corrupted text while scrolling.  So you can HAVE IT ALL!

   
ALTERNATE FIX -- DISABLE MIDDLE MOUSE CLICK AUTOMATICALLY A GIVEN USER USER
   
   The following solution comes from the following webpage:  
   
      https://www.maketecheasier.com/disable-middle-mouse-click-to-paste-feature-in-linux-quick-tips/
      
       1. Open a text editor and add the following text:

             pointer = 1 6 3 4 5 2

          and save the file as “.Xmodmap” (without the quote) in the user's home folder.

       2. Log out of your session and login again. Your mouse middle click will not be
          functional now.

   The above fix can be applied by simply leaving the .Xmodmap file in the user's home folder prior to initial login.  Renaming or deleting the file and re-login should restore the default OS behavior.
   
