forked from tinymce/tinymce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tinymce#1128 in TINYMCE/tinymce from TINY-2995 to …
…master * commit '3159858553586d8a5aef83d153ef2854218267e6': TINY-2995: added missing license header TINY-2995: added more tests TINY-2995: updated changelog TINY-2995: fixed typos in test TINY-2995: added cef override for home/end keys
- Loading branch information
Showing
6 changed files
with
157 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (c) Tiny Technologies, Inc. All rights reserved. | ||
* Licensed under the LGPL or a commercial license. | ||
* For LGPL see License.txt in the project root for license information. | ||
* For commercial licenses see https://www.tiny.cloud/ | ||
*/ | ||
|
||
import * as CefNavigation from './CefNavigation'; | ||
import MatchKeys from './MatchKeys'; | ||
import VK from '../api/util/VK'; | ||
import { Editor } from 'tinymce/core/api/Editor'; | ||
import { KeyboardEvent } from '@ephox/dom-globals'; | ||
|
||
const executeKeydownOverride = (editor: Editor, evt: KeyboardEvent) => { | ||
MatchKeys.execute([ | ||
{ keyCode: VK.END, action: CefNavigation.moveToLineEndPoint(editor, true) }, | ||
{ keyCode: VK.HOME, action: CefNavigation.moveToLineEndPoint(editor, false) } | ||
], evt).each((_) => { | ||
evt.preventDefault(); | ||
}); | ||
}; | ||
|
||
const setup = (editor: Editor) => { | ||
editor.on('keydown', (evt) => { | ||
if (evt.isDefaultPrevented() === false) { | ||
executeKeydownOverride(editor, evt); | ||
} | ||
}); | ||
}; | ||
|
||
export default { | ||
setup | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { GeneralSteps, Logger, Pipeline } from '@ephox/agar'; | ||
import { TinyActions, TinyApis, TinyLoader } from '@ephox/mcagar'; | ||
import Theme from 'tinymce/themes/silver/Theme'; | ||
import { UnitTest } from '@ephox/bedrock'; | ||
import VK from 'tinymce/core/api/util/VK'; | ||
|
||
UnitTest.asynctest('browser.tinymce.core.keyboard.HomeEndKeysTest', (success, failure) => { | ||
Theme(); | ||
|
||
TinyLoader.setup((editor, onSuccess, onFailure) => { | ||
const tinyApis = TinyApis(editor); | ||
const tinyActions = TinyActions(editor); | ||
|
||
Pipeline.async({}, [ | ||
tinyApis.sFocus, | ||
Logger.t('Home key', GeneralSteps.sequence([ | ||
Logger.t('Home key should move caret before cef within the same block', GeneralSteps.sequence([ | ||
tinyApis.sSetContent('<p>123</p><p><span contenteditable="false">CEF</span>456</p>'), | ||
tinyApis.sSetCursor([1, 1], 3), | ||
tinyActions.sContentKeystroke(VK.HOME, { }), | ||
tinyApis.sAssertSelection([1, 0], 0, [1, 0], 0) | ||
])), | ||
Logger.t('Home key should move caret from after cef to before cef', GeneralSteps.sequence([ | ||
tinyApis.sSetContent('<p><span contenteditable="false">CEF</span></p>'), | ||
tinyApis.sSetCursor([0], 1), | ||
tinyActions.sContentKeystroke(VK.HOME, { }), | ||
tinyApis.sAssertSelection([0, 0], 0, [0, 0], 0) | ||
])), | ||
Logger.t('Home key should move caret to before cef from the start of range', GeneralSteps.sequence([ | ||
tinyApis.sSetContent('<p>123</p><p><span contenteditable="false">CEF</span>456<br>789</p>'), | ||
tinyApis.sSetSelection([1, 1], 3, [1, 1], 3), | ||
tinyActions.sContentKeystroke(VK.HOME, { }), | ||
tinyApis.sAssertSelection([1, 0], 0, [1, 0], 0) | ||
])), | ||
Logger.t('Home key should not move caret before cef within the same block if there is a BR in between', GeneralSteps.sequence([ | ||
tinyApis.sSetContent('<p>123</p><p><span contenteditable="false">CEF</span><br>456</p>'), | ||
tinyApis.sSetCursor([1, 2], 3), | ||
tinyActions.sContentKeystroke(VK.HOME, { }), | ||
tinyApis.sAssertSelection([1, 2], 3, [1, 2], 3) | ||
])), | ||
Logger.t('Home key should not move caret if there is no cef', GeneralSteps.sequence([ | ||
tinyApis.sSetContent('<p>123</p>'), | ||
tinyApis.sSetCursor([0, 0], 1), | ||
tinyActions.sContentKeystroke(VK.HOME, { }), | ||
tinyApis.sAssertSelection([0, 0], 1, [0, 0], 1) | ||
])) | ||
])), | ||
Logger.t('End key', GeneralSteps.sequence([ | ||
Logger.t('End key should move caret after cef within the same block', GeneralSteps.sequence([ | ||
tinyApis.sSetContent('<p>123<span contenteditable="false">CEF</span></p><p>456</p>'), | ||
tinyApis.sSetCursor([0, 0], 0), | ||
tinyActions.sContentKeystroke(VK.END, { }), | ||
tinyApis.sAssertSelection([0, 2], 1, [0, 2], 1) | ||
])), | ||
Logger.t('End key should move caret from before cef to after cef', GeneralSteps.sequence([ | ||
tinyApis.sSetContent('<p><span contenteditable="false">CEF</span></p>'), | ||
tinyApis.sSetCursor([0], 0), | ||
tinyActions.sContentKeystroke(VK.END, { }), | ||
tinyApis.sAssertSelection([0, 1], 1, [0, 1], 1) | ||
])), | ||
Logger.t('End key should move caret to after cef from the end of range', GeneralSteps.sequence([ | ||
tinyApis.sSetContent('<p>123<br>456<span contenteditable="false">CEF</span></p>'), | ||
tinyApis.sSetSelection([0, 0], 0, [0, 2], 0), | ||
tinyActions.sContentKeystroke(VK.END, { }), | ||
tinyApis.sAssertSelection([0, 4], 1, [0, 4], 1) | ||
])), | ||
Logger.t('End key should not move caret after cef within the same block if there is a BR in between', GeneralSteps.sequence([ | ||
tinyApis.sSetContent('<p>123<br><span contenteditable="false">CEF</span></p><p>456</p>'), | ||
tinyApis.sSetCursor([0, 0], 0), | ||
tinyActions.sContentKeystroke(VK.END, { }), | ||
tinyApis.sAssertSelection([0, 0], 0, [0, 0], 0) | ||
])), | ||
Logger.t('End key should not move caret if there is no cef', GeneralSteps.sequence([ | ||
tinyApis.sSetContent('<p>123</p>'), | ||
tinyApis.sSetCursor([0, 0], 1), | ||
tinyActions.sContentKeystroke(VK.END, { }), | ||
tinyApis.sAssertSelection([0, 0], 1, [0, 0], 1) | ||
])) | ||
])) | ||
], onSuccess, onFailure); | ||
}, { | ||
add_unload_trigger: false, | ||
base_url: '/project/js/tinymce', | ||
indent: false | ||
}, success, failure); | ||
} | ||
); |