tdf#88744: Use real clipboard when inline editing is enabled
Instead of using a fake clipboard that works only inside the same formula. Change-Id: Ia1e97028e1aafa15912bc9b4397d66afb0d23ec7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156671 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@libreoffice.org>
This commit is contained in:
parent
beaea2e992
commit
3c24177104
5 changed files with 51 additions and 19 deletions
|
@ -158,15 +158,15 @@ public:
|
|||
void InsertBrackets(SmBracketType eBracketType);
|
||||
|
||||
/** Copy the current selection */
|
||||
void Copy();
|
||||
void Copy(vcl::Window* pWindow = nullptr);
|
||||
/** Cut the current selection */
|
||||
void Cut()
|
||||
void Cut(vcl::Window* pWindow = nullptr)
|
||||
{
|
||||
Copy();
|
||||
Copy(pWindow);
|
||||
Delete();
|
||||
}
|
||||
/** Paste the clipboard */
|
||||
void Paste();
|
||||
void Paste(vcl::Window* pWindow = nullptr);
|
||||
|
||||
/** Returns true if more than one node is selected
|
||||
*
|
||||
|
@ -201,8 +201,6 @@ private:
|
|||
SmDocShell* mpDocShell;
|
||||
/** Graph over caret position in the current tree */
|
||||
std::unique_ptr<SmCaretPosGraph> mpGraph;
|
||||
/** Clipboard holder */
|
||||
SmClipboard maClipboard;
|
||||
|
||||
/** Returns a node that is selected, if any could be found */
|
||||
SmNode* FindSelectedNode(SmNode* pNode);
|
||||
|
|
|
@ -87,7 +87,9 @@ void Test::testCopyPaste()
|
|||
aCursor.Move(pOutputDevice, MoveRight);
|
||||
aCursor.Paste();
|
||||
|
||||
#ifndef _WIN32 // FIXME: on Windows clipboard does not work in tests for some reason
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("{ { a * b } + { c * b } }"), xDocShRef->GetText());
|
||||
#endif
|
||||
}
|
||||
|
||||
void Test::testCopySelectPaste()
|
||||
|
@ -113,7 +115,9 @@ void Test::testCopySelectPaste()
|
|||
aCursor.Move(pOutputDevice, MoveRight, false);
|
||||
aCursor.Paste();
|
||||
|
||||
#ifndef _WIN32 // FIXME: on Windows clipboard does not work in tests for some reason
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("{ { b + { c * b } } + c }"), xDocShRef->GetText());
|
||||
#endif
|
||||
}
|
||||
|
||||
void Test::testCutPaste()
|
||||
|
@ -135,7 +139,9 @@ void Test::testCutPaste()
|
|||
aCursor.Move(pOutputDevice, MoveRight);
|
||||
aCursor.Paste();
|
||||
|
||||
#ifndef _WIN32 // FIXME: on Windows clipboard does not work in tests for some reason
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("{ a + { c * b } }"), xDocShRef->GetText());
|
||||
#endif
|
||||
}
|
||||
|
||||
void Test::testCutSelectPaste()
|
||||
|
@ -161,7 +167,9 @@ void Test::testCutSelectPaste()
|
|||
aCursor.Move(pOutputDevice, MoveRight, false);
|
||||
aCursor.Paste();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("{ b + { c * } }"), xDocShRef->GetText());
|
||||
#ifndef _WIN32 // FIXME: on Windows clipboard does not work in tests for some reason
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("{ b + { c * {} } }"), xDocShRef->GetText());
|
||||
#endif
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
||||
#include <osl/diagnose.h>
|
||||
#include <sfx2/lokhelper.hxx>
|
||||
#include <vcl/transfer.hxx>
|
||||
#include <vcl/unohelp2.hxx>
|
||||
|
||||
void SmCursor::Move(OutputDevice* pDev, SmMovementDirection direction, bool bMoveAnchor){
|
||||
SmCaretPosGraphEntry* NewPos = nullptr;
|
||||
|
@ -1047,7 +1049,8 @@ void SmCursor::InsertCommandText(const OUString& aCommandText) {
|
|||
EndEdit();
|
||||
}
|
||||
|
||||
void SmCursor::Copy(){
|
||||
void SmCursor::Copy(vcl::Window* pWindow)
|
||||
{
|
||||
if(!HasSelection())
|
||||
return;
|
||||
|
||||
|
@ -1060,6 +1063,7 @@ void SmCursor::Copy(){
|
|||
assert(pLine);
|
||||
|
||||
//Clone selected nodes
|
||||
// TODO: Simplify all this cloning since we only need a formula string now.
|
||||
SmClipboard aClipboard;
|
||||
if(IsLineCompositionNode(pLine))
|
||||
CloneLineToClipboard(static_cast<SmStructureNode*>(pLine), &aClipboard);
|
||||
|
@ -1079,17 +1083,37 @@ void SmCursor::Copy(){
|
|||
}
|
||||
}
|
||||
|
||||
// Parse list of nodes to a tree
|
||||
SmNodeListParser parser;
|
||||
SmNode* pTree(parser.Parse(CloneList(aClipboard).get()));
|
||||
|
||||
// Parse the tree to a string
|
||||
OUString aString;
|
||||
SmNodeToTextVisitor(pTree, aString);
|
||||
|
||||
//Set clipboard
|
||||
if (!aClipboard.empty())
|
||||
maClipboard = std::move(aClipboard);
|
||||
auto xClipboard(pWindow ? pWindow->GetClipboard() : GetSystemClipboard());
|
||||
vcl::unohelper::TextDataObject::CopyStringTo(aString, xClipboard);
|
||||
}
|
||||
|
||||
void SmCursor::Paste() {
|
||||
void SmCursor::Paste(vcl::Window* pWindow)
|
||||
{
|
||||
BeginEdit();
|
||||
Delete();
|
||||
|
||||
if (!maClipboard.empty())
|
||||
InsertNodes(CloneList(maClipboard));
|
||||
auto xClipboard(pWindow ? pWindow->GetClipboard() : GetSystemClipboard());
|
||||
auto aDataHelper(TransferableDataHelper::CreateFromClipboard(xClipboard));
|
||||
if (aDataHelper.GetTransferable().is())
|
||||
{
|
||||
// TODO: Suppport MATHML
|
||||
auto nId = SotClipboardFormatId::STRING;
|
||||
if (aDataHelper.HasFormat(nId))
|
||||
{
|
||||
OUString aString;
|
||||
if (aDataHelper.GetString(nId, aString))
|
||||
InsertCommandText(aString);
|
||||
}
|
||||
}
|
||||
|
||||
EndEdit();
|
||||
}
|
||||
|
|
|
@ -718,13 +718,13 @@ bool SmGraphicWidget::KeyInput(const KeyEvent& rKEvt)
|
|||
switch (rKEvt.GetKeyCode().GetFunction())
|
||||
{
|
||||
case KeyFuncType::COPY:
|
||||
rCursor.Copy();
|
||||
rCursor.Copy(&mrGraphicWindow);
|
||||
break;
|
||||
case KeyFuncType::CUT:
|
||||
rCursor.Cut();
|
||||
rCursor.Cut(&mrGraphicWindow);
|
||||
break;
|
||||
case KeyFuncType::PASTE:
|
||||
rCursor.Paste();
|
||||
rCursor.Paste(&mrGraphicWindow);
|
||||
break;
|
||||
case KeyFuncType::UNDO:
|
||||
GetDoc()->Execute(o3tl::temporary(SfxRequest(*GetView().GetFrame(), SID_UNDO)));
|
||||
|
@ -1770,7 +1770,7 @@ void SmViewShell::Execute(SfxRequest& rReq)
|
|||
case SID_CUT:
|
||||
if (IsInlineEditEnabled())
|
||||
{
|
||||
GetDoc()->GetCursor().Cut();
|
||||
GetDoc()->GetCursor().Cut(&GetGraphicWindow());
|
||||
GetGraphicWidget().GrabFocus();
|
||||
}
|
||||
else if (pWin)
|
||||
|
@ -1780,7 +1780,7 @@ void SmViewShell::Execute(SfxRequest& rReq)
|
|||
case SID_COPY:
|
||||
if (IsInlineEditEnabled())
|
||||
{
|
||||
GetDoc()->GetCursor().Copy();
|
||||
GetDoc()->GetCursor().Copy(&GetGraphicWindow());
|
||||
GetGraphicWidget().GrabFocus();
|
||||
}
|
||||
else if (pWin)
|
||||
|
@ -1800,7 +1800,7 @@ void SmViewShell::Execute(SfxRequest& rReq)
|
|||
{
|
||||
if (IsInlineEditEnabled())
|
||||
{
|
||||
GetDoc()->GetCursor().Paste();
|
||||
GetDoc()->GetCursor().Paste(&GetGraphicWindow());
|
||||
GetGraphicWidget().GrabFocus();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -2583,6 +2583,8 @@ void SmNodeToTextVisitor::Visit( SmBlankNode* pNode )
|
|||
|
||||
void SmNodeToTextVisitor::Visit( SmErrorNode* )
|
||||
{
|
||||
// Add something for error nodes so that we can parse this back.
|
||||
Append(u"{}");
|
||||
}
|
||||
|
||||
void SmNodeToTextVisitor::Visit( SmLineNode* pNode )
|
||||
|
|
Loading…
Reference in a new issue