summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@libreoffice.org>2023-09-04 13:22:04 +0300
committerخالد حسني <khaled@libreoffice.org>2023-09-04 19:29:45 +0200
commit065609f86f730d4eedc6b7ae28382dc7daea11ac (patch)
tree30b881ac7b0a192ec57b25bf6ab3e916a07a2105 /starmath
parentf80c2c70756e3620daed6675c8546caca4153d4b (diff)
starmath: Make cut/copy/paste buttons work with inline editing
Check for visual cursor selection when in inline editing mode, and update edit window when updating visual cursor. Change-Id: Id1a259b67db47eea0b36b55d08ef5dc5f8aa8246 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156513 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@libreoffice.org>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/inc/cursor.hxx1
-rw-r--r--starmath/source/cursor.cxx7
-rw-r--r--starmath/source/view.cxx64
3 files changed, 66 insertions, 6 deletions
diff --git a/starmath/inc/cursor.hxx b/starmath/inc/cursor.hxx
index 0a8a35071f10..7e1f8ec83c53 100644
--- a/starmath/inc/cursor.hxx
+++ b/starmath/inc/cursor.hxx
@@ -85,6 +85,7 @@ public:
/** True, if the cursor has a selection */
bool HasSelection() const { return mpAnchor != mpPosition; }
+ const ESelection& GetSelection();
/** Move the position of this cursor */
void Move(OutputDevice* pDev, SmMovementDirection direction, bool bMoveAnchor = true);
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index e8623517bcd7..41506dff3109 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -1141,6 +1141,13 @@ SmNode* SmCursor::FindSelectedNode(SmNode* pNode){
return nullptr;
}
+const ESelection& SmCursor::GetSelection() {
+ const SmNode* pNode = FindSelectedNode(mpTree);
+ if (!pNode)
+ return mpTree->GetSelection();
+ return pNode->GetSelection();
+}
+
void SmCursor::LineToList(SmStructureNode* pLine, SmNodeList& list){
for(auto pChild : *pLine)
{
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index 85dccb711ec6..22ca4e575d3b 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -368,8 +368,13 @@ bool SmGraphicWidget::MouseButtonDown(const MouseEvent& rMEvt)
if (!pTree)
return true;
+ SmEditWindow* pEdit = GetView().GetEditWindow();
+
if (SmViewShell::IsInlineEditEnabled()) {
- GetCursor().MoveTo(&rDevice, aPos, !rMEvt.IsShift());
+ SmCursor& rCursor = GetCursor();
+ rCursor.MoveTo(&rDevice, aPos, !rMEvt.IsShift());
+ if (pEdit)
+ pEdit->SetSelection(rCursor.GetSelection());
// 'on grab' window events are missing in lok, do it explicitly
if (comphelper::LibreOfficeKit::isActive())
SetIsCursorVisible(true);
@@ -383,7 +388,6 @@ bool SmGraphicWidget::MouseButtonDown(const MouseEvent& rMEvt)
if (!pNode)
return true;
- SmEditWindow* pEdit = GetView().GetEditWindow();
if (!pEdit)
return true;
@@ -713,6 +717,7 @@ bool SmGraphicWidget::KeyInput(const KeyEvent& rKEvt)
return GetView().KeyInput(rKEvt);
bool bConsumed = true;
+ bool bSetSelection = false;
SmCursor& rCursor = GetCursor();
switch (rKEvt.GetKeyCode().GetFunction())
@@ -737,24 +742,32 @@ bool SmGraphicWidget::KeyInput(const KeyEvent& rKEvt)
{
case KEY_LEFT:
rCursor.Move(&GetOutputDevice(), MoveLeft, !rKEvt.GetKeyCode().IsShift());
+ bSetSelection = true;
break;
case KEY_RIGHT:
rCursor.Move(&GetOutputDevice(), MoveRight, !rKEvt.GetKeyCode().IsShift());
+ bSetSelection = true;
break;
case KEY_UP:
rCursor.Move(&GetOutputDevice(), MoveUp, !rKEvt.GetKeyCode().IsShift());
+ bSetSelection = true;
break;
case KEY_DOWN:
rCursor.Move(&GetOutputDevice(), MoveDown, !rKEvt.GetKeyCode().IsShift());
+ bSetSelection = true;
break;
case KEY_RETURN:
if (!rKEvt.GetKeyCode().IsShift())
+ {
rCursor.InsertRow();
+ bSetSelection = true;
+ }
break;
case KEY_DELETE:
if (!rCursor.HasSelection())
{
rCursor.Move(&GetOutputDevice(), MoveRight, false);
+ bSetSelection = true;
if (rCursor.HasComplexSelection())
break;
}
@@ -762,12 +775,17 @@ bool SmGraphicWidget::KeyInput(const KeyEvent& rKEvt)
break;
case KEY_BACKSPACE:
rCursor.DeletePrev(&GetOutputDevice());
+ bSetSelection = true;
break;
default:
if (!CharInput(rKEvt.GetCharCode(), rCursor, GetOutputDevice()))
bConsumed = GetView().KeyInput(rKEvt);
}
}
+
+ SmEditWindow* pEdit = GetView().GetEditWindow();
+ if (pEdit && bSetSelection)
+ pEdit->SetSelection(rCursor.GetSelection());
CaretBlinkStop();
CaretBlinkStart();
SetIsCursorVisible(true);
@@ -1766,12 +1784,22 @@ void SmViewShell::Execute(SfxRequest& rReq)
case SID_CUT:
- if (pWin)
+ if (IsInlineEditEnabled() && !mbInsertIntoEditWindow)
+ {
+ GetDoc()->GetCursor().Cut();
+ GetGraphicWidget().GrabFocus();
+ }
+ else if (pWin)
pWin->Cut();
break;
case SID_COPY:
- if (pWin)
+ if (IsInlineEditEnabled() && !mbInsertIntoEditWindow)
+ {
+ GetDoc()->GetCursor().Copy();
+ GetGraphicWidget().GrabFocus();
+ }
+ else if (pWin)
{
if (pWin->IsAllSelected())
{
@@ -1786,6 +1814,13 @@ void SmViewShell::Execute(SfxRequest& rReq)
case SID_PASTE:
{
+ if (IsInlineEditEnabled() && !mbInsertIntoEditWindow)
+ {
+ GetDoc()->GetCursor().Paste();
+ GetGraphicWidget().GrabFocus();
+ break;
+ }
+
bool bCallExec = nullptr == pWin;
if( !bCallExec )
{
@@ -1812,7 +1847,19 @@ void SmViewShell::Execute(SfxRequest& rReq)
break;
case SID_DELETE:
- if (pWin)
+ if (IsInlineEditEnabled() && !mbInsertIntoEditWindow)
+ {
+ if (!GetDoc()->GetCursor().HasSelection())
+ {
+ GetDoc()->GetCursor().Move(&GetGraphicWindow().GetGraphicWidget().GetOutputDevice(), MoveRight, false);
+ if (!GetDoc()->GetCursor().HasComplexSelection())
+ GetDoc()->GetCursor().Delete();
+ }
+ else
+ GetDoc()->GetCursor().Delete();
+ GetGraphicWidget().GrabFocus();
+ }
+ else if (pWin)
pWin->Delete();
break;
@@ -2095,7 +2142,12 @@ void SmViewShell::GetState(SfxItemSet &rSet)
case SID_CUT:
case SID_COPY:
case SID_DELETE:
- if (! pEditWin || ! pEditWin->IsSelected())
+ if (IsInlineEditEnabled() && !mbInsertIntoEditWindow)
+ {
+ if (!GetDoc()->GetCursor().HasSelection())
+ rSet.DisableItem(nWh);
+ }
+ else if (! pEditWin || ! pEditWin->IsSelected())
rSet.DisableItem(nWh);
break;