CRASTELLA / texmaker

Automatically exported from code.google.com/p/texmaker
0 stars 0 forks source link

ampersands inserted when used right click spellcheck suggestions #1494

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile texmaker with Qt 5.4.1
2. Open texmaker and create a new document. Type "testt"
3. Right click on "testt" so that the spelling suggestions pop up, and select 
"test"

What is the expected output? What do you see instead?
The expected output is "test", but what I see is "t&est"

What version of the product are you using? On what operating system?
I have tested this with several versions of texmaker and tracked the problem 
down to a new feature of Qt 5.

Please provide any additional information below.
The shortcuts feature of Qt5 automatically creates keyboard shortcuts coded by 
inserting an ampersand before the letter of the shortcut (see: 
http://doc.qt.digia.com/qt-5.2/qshortcut.html#details)

In latexeditor.cpp on 958 of version 4.4.1 there is a function:
void LatexEditor::correctWord()
{
QAction *action = qobject_cast<QAction *>(sender());
if (action)
    {
    QString newword = action->text();
    replace(newword,false,"");
    }
}

When the action->text() is called the result has the ampersand inserted. I am 
looking for a way of getting the text without the ampersand.

QUOTE:
On certain widgets, using '&' in front of a character will automatically create 
a mnemonic (a shortcut) for that character, e.g. "E&xit" will create the 
shortcut Alt+X (use '&&' to display an actual ampersand). The widget might 
consume and perform an action on a given shortcut. On X11 the ampersand will 
not be shown and the character will be underlined. On Windows, shortcuts are 
normally not displayed until the user presses the Alt key, but this is a 
setting the user can change. On Mac, shortcuts are disabled by default. Call 
qt_set_sequence_auto_mnemonic() to enable them. However, because mnemonic 
shortcuts do not fit in with Aqua's guidelines, Qt will not show the shortcut 
character underlined.
:END of QUOTE

Original issue reported on code.google.com by verta...@gmail.com on 13 May 2015 at 9:04

GoogleCodeExporter commented 9 years ago
I have written a patch which fixes the problem but it is ugly so you all may 
want to implement it a different way. I will include it as the next comment.

Original comment by verta...@gmail.com on 15 May 2015 at 2:35

GoogleCodeExporter commented 9 years ago
Description: fixed a bug which inserts ampersands on spellcheck replace
 Qt5 added an automatic keyboard shortcut feature which inserts & symbols
 into menu labels representing which letter is a keyboard shortcut for
 that action. I added a QMap which associates the QAction pointer with
 the spelling suggestion so that the unmodified suggestion is inserted
 without the ampersand.
 .
 texmaker (4.4.1-1) unstable; urgency=medium
 .
   * New upstream release.
   * Refresh patches offset.
   * d/copyright: Remove files that
     aren't included by upstream anymore.
   * Bump Standards-Version to 3.9.6 (no changes).
Author: Julián Moreno Patiño <julian@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- texmaker-4.4.1.orig/latexeditor.cpp
+++ texmaker-4.4.1/latexeditor.cpp
@@ -26,6 +26,7 @@
 #include <QKeyEvent>
 #include <QAbstractItemView>
 #include <QApplication>
+#include <QMap>
 #include <QModelIndex>
 #include <QAbstractItemModel>
 #include <QScrollBar>
@@ -44,6 +45,8 @@

 #include "blockdata.h"

+QMap<QAction*,QString> spellingLookup;
+
 static void convertToPlainText(QString &txt)
 {
     QChar *uc = txt.data();
@@ -858,6 +861,7 @@ if (inlinecheckSpelling && pChecker && !
                if (ns > 0)
                    {
                    suggWords.clear();
+                    spellingLookup.clear();
                    for (int i=0; i < ns; i++) 
                        {
                        suggWords.append(codec->toUnicode(wlst[i]));
@@ -872,8 +876,12 @@ if (inlinecheckSpelling && pChecker && !
                            {
                            foreach (const QString &suggestion, suggWords)
                                {
-                               a = menu->addAction(suggestion, this, SLOT(correctWord()));
+                               a = menu->addAction(suggestion, this, SLOT(correctWord()),
+                                                                0
+                                                            );
                                a->setFont(spellmenufont);
+                                                            
a->setText(suggestion);
+                                spellingLookup.insert(a,suggestion);
                                }
                            }
                        }
@@ -957,8 +965,8 @@ void LatexEditor::correctWord()
 {
 QAction *action = qobject_cast<QAction *>(sender());
 if (action)
-   {
-   QString newword = action->text();
+   {    
+   QString newword = spellingLookup.find(action).value();
    replace(newword,false,"");
    }
 }

Original comment by verta...@gmail.com on 15 May 2015 at 2:37