mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #32114 from overleaf/mg-context-menu-cursor-movemenet
Move cursor on right-click within same line GitOrigin-RevId: 8b622e9f557ecb1a33b7ba1a80d5752e05a72718
This commit is contained in:
+55
@@ -162,6 +162,61 @@ describe('editor context menu', { scrollBehavior: false }, function () {
|
||||
cy.findByRole('menu').should('not.exist')
|
||||
})
|
||||
|
||||
it('should move the cursor when right-clicking a different position on the same line', function () {
|
||||
grantClipboardPermissions()
|
||||
|
||||
const pasteContent = 'XX'
|
||||
const scope = mockScope()
|
||||
|
||||
cy.mount(
|
||||
<TestContainer>
|
||||
<EditorProviders scope={scope}>
|
||||
<CodeMirrorEditor />
|
||||
</EditorProviders>
|
||||
</TestContainer>
|
||||
)
|
||||
|
||||
// Stub clipboard to return known content for pasting
|
||||
cy.window().then(win => {
|
||||
const getTypeStub = cy.stub()
|
||||
getTypeStub
|
||||
.withArgs('text/plain')
|
||||
.resolves(new Blob([pasteContent], { type: 'text/plain' }))
|
||||
|
||||
cy.stub(win.navigator.clipboard, 'read').resolves([
|
||||
{
|
||||
types: ['text/plain'],
|
||||
getType: getTypeStub,
|
||||
},
|
||||
])
|
||||
cy.stub(win.navigator.clipboard, 'readText').resolves(pasteContent)
|
||||
})
|
||||
|
||||
cy.get('.cm-line').eq(16).as('line')
|
||||
cy.get('@line').click()
|
||||
cy.get('@line').type('aaaa bbbb')
|
||||
|
||||
// Right-click the left side of the line — opens context menu with cursor near start
|
||||
cy.get('@line').rightclick('left')
|
||||
cy.findByRole('menu').should('be.visible')
|
||||
|
||||
// Right-click the right side of the same line while menu is still open —
|
||||
// cursor should move to the end of the line
|
||||
cy.get('@line').rightclick('right')
|
||||
cy.findByRole('menu').should('be.visible')
|
||||
|
||||
// Paste via context menu — content goes wherever the cursor is
|
||||
cy.findByRole('menu').within(() => {
|
||||
cy.findByRole('menuitem', { name: pasteLabelMatcher }).click()
|
||||
})
|
||||
|
||||
// If cursor moved: "aaaa bbbbXX" (pasted at end)
|
||||
cy.get('@line').should($line => {
|
||||
const text = $line.text()
|
||||
expect(text).to.equal('aaaa bbbb' + pasteContent)
|
||||
})
|
||||
})
|
||||
|
||||
it('should should close when clicking outside the editor', function () {
|
||||
const scope = mockScope()
|
||||
const outsideEditorButtonName = 'Recompile'
|
||||
|
||||
Reference in New Issue
Block a user