patch 9.1.0494: Wrong matched text highlighted in pum with 'rightleft'

Problem:  Wrong matched text highlighted in pum with 'rightleft'.
Solution: Match using the original text instead of the reversed text.
          (zeertzjq)

closes: #15020

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim
index b9c6b92..d1fa5a9 100644
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -1390,6 +1390,7 @@
       return {
             \ 'words': [
             \ { 'word': 'foo', 'kind': 'fookind' },
+            \ { 'word': 'foofoo', 'kind': 'fookind' },
             \ { 'word': 'foobar', 'kind': 'fookind' },
             \ { 'word': 'fooBaz', 'kind': 'fookind' },
             \ { 'word': 'foobala', 'kind': 'fookind' },
@@ -1401,7 +1402,7 @@
     endfunc
     set omnifunc=Omni_test
     set completeopt=menu,noinsert,fuzzy
-    hi PmenuMatchSel  ctermfg=6 ctermbg=225
+    hi PmenuMatchSel  ctermfg=6 ctermbg=7
     hi PmenuMatch     ctermfg=4 ctermbg=225
   END
   call writefile(lines, 'Xscript', 'D')
@@ -1412,7 +1413,7 @@
   call term_sendkeys(buf, "fo")
   call TermWait(buf, 50)
   call VerifyScreenDump(buf, 'Test_pum_highlights_03', {})
-  call term_sendkeys(buf, "\<ESC>S\<C-x>\<C-O>")
+  call term_sendkeys(buf, "\<Esc>S\<C-X>\<C-O>")
   call TermWait(buf, 50)
   call term_sendkeys(buf, "你")
   call TermWait(buf, 50)
@@ -1420,28 +1421,48 @@
   call term_sendkeys(buf, "吗")
   call TermWait(buf, 50)
   call VerifyScreenDump(buf, 'Test_pum_highlights_05', {})
+  call term_sendkeys(buf, "\<C-E>\<Esc>")
 
   if has('rightleft')
-    call term_sendkeys(buf, "\<C-E>\<ESC>u:set rightleft\<CR>")
+    call term_sendkeys(buf, ":set rightleft\<CR>")
     call TermWait(buf, 50)
-    call term_sendkeys(buf, "i\<C-X>\<C-O>")
+    call term_sendkeys(buf, "S\<C-X>\<C-O>")
     call TermWait(buf, 50)
     call term_sendkeys(buf, "fo")
     call TermWait(buf, 50)
     call VerifyScreenDump(buf, 'Test_pum_highlights_06', {})
-    call term_sendkeys(buf, "\<C-E>\<ESC>u:set norightleft\<CR>")
+    call term_sendkeys(buf, "\<Esc>S\<C-X>\<C-O>")
+    call TermWait(buf, 50)
+    call term_sendkeys(buf, "你")
+    call VerifyScreenDump(buf, 'Test_pum_highlights_06a', {})
+    call term_sendkeys(buf, "吗")
+    call VerifyScreenDump(buf, 'Test_pum_highlights_06b', {})
+    call term_sendkeys(buf, "\<C-E>\<Esc>")
+    call term_sendkeys(buf, ":set norightleft\<CR>")
     call TermWait(buf)
   endif
 
   call term_sendkeys(buf, ":set completeopt-=fuzzy\<CR>")
   call TermWait(buf)
-  call term_sendkeys(buf, "\<ESC>S\<C-x>\<C-O>")
+  call term_sendkeys(buf, "S\<C-X>\<C-O>")
   call TermWait(buf, 50)
   call term_sendkeys(buf, "fo")
   call TermWait(buf, 50)
   call VerifyScreenDump(buf, 'Test_pum_highlights_07', {})
+  call term_sendkeys(buf, "\<C-E>\<Esc>")
 
-  call term_sendkeys(buf, "\<C-E>\<Esc>u")
+  if has('rightleft')
+    call term_sendkeys(buf, ":set rightleft\<CR>")
+    call TermWait(buf, 50)
+    call term_sendkeys(buf, "S\<C-X>\<C-O>")
+    call TermWait(buf, 50)
+    call term_sendkeys(buf, "fo")
+    call TermWait(buf, 50)
+    call VerifyScreenDump(buf, 'Test_pum_highlights_08', {})
+    call term_sendkeys(buf, "\<C-E>\<Esc>")
+    call term_sendkeys(buf, ":set norightleft\<CR>")
+  endif
+
   call TermWait(buf)
   call StopVimInTerminal(buf)
 endfunc