#8055 add support for system-wide find buffer on Mac

Command-E is standard for paste to find buffer on Mac. That's why the key binding is changed appropriately.
This commit is contained in:
Stephan Witt 2021-02-14 18:56:25 +01:00
parent 0bd9a8be3d
commit a476cc4839
8 changed files with 82 additions and 17 deletions

View File

@ -139,8 +139,9 @@ Format 5
\bind "C-d" "buffer-view dvi" # 'd' for dvi
\bind "C-M-d" "command-alternatives master-buffer-view dvi; buffer.view dvi"
\bind "C-S-D" "buffer-update dvi" # 'd' for dvi
# -: "Command-E" # Use the selection for a find
\bind "C-e" "font-emph"
# +: "Command-E" # Use the selection for a find
\bind "C-e" "search-string-set"
\bind "C-M-e" "font-emph"
# +: "Command-F" # Open a Find window
\bind "C-f" "dialog-toggle findreplace"
\bind "C-S-f" "dialog-toggle findreplaceadv"

View File

@ -61,6 +61,7 @@
#include "frontends/NullPainter.h"
#include "frontends/Painter.h"
#include "frontends/Selection.h"
#include "frontends/Clipboard.h"
#include "support/convert.h"
#include "support/debug.h"
@ -274,9 +275,6 @@ struct BufferView::Private
*/
frontend::GuiBufferViewDelegate * gui_;
/// cache search string for simple search
docstring search_request_cache_;
///
map<string, Inset *> edited_insets_;
@ -449,6 +447,22 @@ Buffer const & BufferView::buffer() const
}
docstring const & BufferView::searchRequestCache() const
{
return theClipboard().getFindBuffer();
}
void BufferView::setSearchRequestCache(docstring const & text)
{
bool casesensitive;
bool matchword;
bool forward;
docstring const search = string2find(text, casesensitive, matchword, forward);
theClipboard().setFindBuffer(search);
}
bool BufferView::needsFitCursor() const
{
if (cursorStatus(d->cursor_) == CUR_INSIDE) {
@ -1620,21 +1634,17 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
docstring searched_string;
if (!cmd.argument().empty()) {
d->search_request_cache_ = cmd.argument();
setSearchRequestCache(cmd.argument());
searched_string = cmd.argument();
} else {
searched_string = d->search_request_cache_;
searched_string = searchRequestCache();
}
if (searched_string.empty())
break;
bool casesensitive;
bool matchword;
bool forward;
docstring const search = string2find(searched_string, casesensitive, matchword, forward);
docstring const data =
find2string(search, casesensitive, matchword, act == LFUN_WORD_FIND_FORWARD);
find2string(searched_string, false, false, act == LFUN_WORD_FIND_FORWARD);
bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
if (found)
dr.screenUpdate(Update::Force | Update::FitCursor);
@ -1645,8 +1655,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
case LFUN_WORD_FIND: {
docstring arg = cmd.argument();
if (arg.empty() && !d->search_request_cache_.empty())
arg = d->search_request_cache_;
if (arg.empty())
arg = searchRequestCache();
if (arg.empty()) {
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
break;
@ -1656,14 +1666,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
else
dr.setMessage(_("Search string not found!"));
d->search_request_cache_ = arg;
setSearchRequestCache(arg);
break;
}
case LFUN_SEARCH_STRING_SET: {
docstring pattern = cmd.argument();
if (!pattern.empty()) {
d->search_request_cache_ = pattern;
setSearchRequestCache(pattern);
break;
}
if (cur.selection())
@ -1675,7 +1685,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
cur.selection(false);
cur.pos() = spos;
}
d->search_request_cache_ = pattern;
setSearchRequestCache(pattern);
break;
}

View File

@ -109,6 +109,9 @@ public:
/// bottom margin
int bottomMargin() const;
docstring const & searchRequestCache() const;
void setSearchRequestCache(docstring const & text);
/// return the on-screen size of this length
/*
* This is a wrapper around Length::inPixels that uses the

View File

@ -65,6 +65,8 @@ public:
/// Get the contents of the window system clipboard as graphics file.
virtual support::FileName getAsGraphics(Cursor const & cur, GraphicsType type) const = 0;
virtual docstring const & getFindBuffer() { return find_buffer_; }
/**
* Fill the system clipboard. The format of \p lyx is as written in
* .lyx files, the format of \p text is plain text.
@ -79,6 +81,8 @@ public:
/// Put a general string on the system clipboard (not LyX text)
virtual void put(std::string const & text) const = 0;
virtual void setFindBuffer(docstring const & text) { find_buffer_ = text;}
/// Does the clipboard contain text contents?
virtual bool hasTextContents(TextType type = AnyTextType) const = 0;
/// Does the clipboard contain graphics contents of a certain type?
@ -94,6 +98,9 @@ public:
/// \returns true if both the LyX and the plaintext versions of the
/// clipboard are empty, and no supported graphics format is available.
virtual bool empty() const = 0;
private:
docstring find_buffer_;
};
} // namespace frontend

View File

@ -12,6 +12,7 @@
#include <config.h>
#include "GuiApplication.h"
#include "GuiClipboard.h"
#include "Buffer.h"
@ -111,6 +112,11 @@ GuiClipboard::GuiClipboard()
{
connect(qApp->clipboard(), SIGNAL(dataChanged()),
this, SLOT(on_dataChanged()));
if(qApp->clipboard()->supportsFindBuffer()) {
connect(qApp->clipboard(), SIGNAL(findBufferChanged()),
this, SLOT(on_findChanged()));
on_findChanged();
}
// initialize clipboard status.
update();
}
@ -544,6 +550,21 @@ bool GuiClipboard::hasInternal() const
}
void GuiClipboard::setFindBuffer(docstring const & text)
{
LYXERR(Debug::CLIPBOARD, "new findbuffer: " << text);
Clipboard::setFindBuffer(text);
qApp->clipboard()->setText(toqstr(text), QClipboard::FindBuffer);
}
void GuiClipboard::on_findChanged()
{
Clipboard::setFindBuffer(from_utf8(fromqstr(
qApp->clipboard()->text(QClipboard::FindBuffer))));
}
void GuiClipboard::on_dataChanged()
{
update();

View File

@ -82,8 +82,11 @@ public:
support::FileName getPastedGraphicsFileName(Cursor const & cur,
Clipboard::GraphicsType & type) const;
void setFindBuffer(docstring const & text) override;
private Q_SLOTS:
void on_dataChanged();
void on_findChanged();
void update();
private:

View File

@ -12,6 +12,7 @@
#include <config.h>
#include "GuiApplication.h"
#include "GuiSearch.h"
#include "lyxfind.h"
@ -28,8 +29,11 @@
#include "support/debug.h"
#include "support/gettext.h"
#include "support/debug.h"
#include "frontends/alert.h"
#include "frontends/Clipboard.h"
#include <QClipboard>
#include <QLineEdit>
#include <QSettings>
#include <QShowEvent>
@ -71,6 +75,11 @@ GuiSearchWidget::GuiSearchWidget(QWidget * parent)
connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
connect(findCO, SIGNAL(editTextChanged(QString)),
this, SLOT(findChanged()));
if(qApp->clipboard()->supportsFindBuffer()) {
connect(qApp->clipboard(), SIGNAL(findBufferChanged()),
this, SLOT(findBufferChanged()));
findBufferChanged();
}
setFocusProxy(findCO);
@ -149,6 +158,16 @@ void GuiSearchWidget::showEvent(QShowEvent * e)
}
void GuiSearchWidget::findBufferChanged()
{
docstring search = theClipboard().getFindBuffer();
if (!search.empty()) {
LYXERR(Debug::CLIPBOARD, "from findbuffer: " << search);
findCO->setCurrentText(toqstr(search));
}
}
void GuiSearchWidget::findChanged()
{
findPB->setEnabled(!findCO->currentText().isEmpty());

View File

@ -42,6 +42,7 @@ public:
private Q_SLOTS:
void findChanged();
void findBufferChanged();
void findClicked(bool const backwards = false);
void findPrevClicked();
void replaceClicked(bool const backwards = false);