Search in sources :

Example 1 with MonacoStandaloneCodeEditor

use of org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor in project kie-wb-common by kiegroup.

the class MonacoEditorDOMElement method setupInternalComponent.

void setupInternalComponent() {
    final Style style = widget.getElement().getStyle();
    style.setWidth(100, PCT);
    style.setHeight(100, PCT);
    final MonacoPropertiesFactory properties = makeMonacoPropertiesFactory();
    final MonacoStandaloneCodeEditor codeEditor = getMonacoEditor().create(uncheckedCast(widget.getElement()), properties.getConstructionOptions());
    codeEditor.onKeyDown(getOnKeyDown(codeEditor));
    codeEditor.onDidBlurEditorWidget(getWidgetTrigger(getBlurEvent()));
    widget.setCodeEditor(codeEditor);
    widget.setFocus(true);
}
Also used : MonacoPropertiesFactory(org.kie.workbench.common.dmn.client.widgets.codecompletion.MonacoPropertiesFactory) Style(com.google.gwt.dom.client.Style) MonacoStandaloneCodeEditor(org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor)

Example 2 with MonacoStandaloneCodeEditor

use of org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor in project kie-wb-common by kiegroup.

the class MonacoEditorDOMElementTest method testGetOnKeyDownWhenSuggestWidgetIsVisibleAndKeyCodeIsEsc.

@Test
public void testGetOnKeyDownWhenSuggestWidgetIsVisibleAndKeyCodeIsEsc() {
    final MonacoStandaloneCodeEditor codeEditor = mock(MonacoStandaloneCodeEditor.class);
    final NativeEvent event = mock(NativeEvent.class);
    when(event.getKeyCode()).thenReturn(9);
    when(codeEditor.isSuggestWidgetVisible()).thenReturn(true);
    domElement.getOnKeyDown(codeEditor).call(event);
    verify(codeEditor).trigger("keyboard", "cursorHome");
    verify(codeEditor).trigger("keyboard", "cursorEnd");
    verify(event).stopPropagation();
    verify(event).preventDefault();
}
Also used : MonacoStandaloneCodeEditor(org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor) NativeEvent(com.google.gwt.dom.client.NativeEvent) Test(org.junit.Test)

Example 3 with MonacoStandaloneCodeEditor

use of org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor in project kie-wb-common by kiegroup.

the class MonacoEditorDOMElementTest method testGetOnKeyDownWhenSuggestWidgetIsNotVisibleAndKeyCodeIsNotEsc.

@Test
public void testGetOnKeyDownWhenSuggestWidgetIsNotVisibleAndKeyCodeIsNotEsc() {
    final MonacoStandaloneCodeEditor codeEditor = mock(MonacoStandaloneCodeEditor.class);
    final NativeEvent event = mock(NativeEvent.class);
    when(event.getKeyCode()).thenReturn(10);
    when(codeEditor.isSuggestWidgetVisible()).thenReturn(false);
    domElement.getOnKeyDown(codeEditor).call(event);
    verify(codeEditor, never()).trigger("keyboard", "cursorHome");
    verify(codeEditor, never()).trigger("keyboard", "cursorEnd");
    verify(event, never()).stopPropagation();
    verify(event, never()).preventDefault();
}
Also used : MonacoStandaloneCodeEditor(org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor) NativeEvent(com.google.gwt.dom.client.NativeEvent) Test(org.junit.Test)

Example 4 with MonacoStandaloneCodeEditor

use of org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor in project kie-wb-common by kiegroup.

the class MonacoEditorDOMElementTest method testGetOnKeyDownWhenSuggestWidgetIsVisibleAndKeyCodeIsNotEsc.

@Test
public void testGetOnKeyDownWhenSuggestWidgetIsVisibleAndKeyCodeIsNotEsc() {
    final MonacoStandaloneCodeEditor codeEditor = mock(MonacoStandaloneCodeEditor.class);
    final NativeEvent event = mock(NativeEvent.class);
    when(event.getKeyCode()).thenReturn(10);
    when(codeEditor.isSuggestWidgetVisible()).thenReturn(true);
    domElement.getOnKeyDown(codeEditor).call(event);
    verify(codeEditor, never()).trigger("keyboard", "cursorHome");
    verify(codeEditor, never()).trigger("keyboard", "cursorEnd");
    verify(event, never()).stopPropagation();
    verify(event, never()).preventDefault();
}
Also used : MonacoStandaloneCodeEditor(org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor) NativeEvent(com.google.gwt.dom.client.NativeEvent) Test(org.junit.Test)

Example 5 with MonacoStandaloneCodeEditor

use of org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor in project kie-wb-common by kiegroup.

the class MonacoEditorDOMElementTest method testSetupInternalComponent.

@Test
public void testSetupInternalComponent() {
    final Element element = mock(Element.class);
    final Style style = mock(Style.class);
    final elemental2.dom.Element mockedElement = mock(elemental2.dom.Element.class);
    final MonacoPropertiesFactory properties = mock(MonacoPropertiesFactory.class);
    final JavaScriptObject constructionOptions = mock(JavaScriptObject.class);
    final MonacoEditor editor = mock(MonacoEditor.class);
    final MonacoStandaloneCodeEditor standaloneCodeEditor = mock(MonacoStandaloneCodeEditor.class);
    final com.google.gwt.user.client.Element gwtElement = mock(com.google.gwt.user.client.Element.class);
    final MonacoStandaloneCodeEditor.CallbackFunction onKeyDown = mock(MonacoStandaloneCodeEditor.CallbackFunction.class);
    final MonacoStandaloneCodeEditor.CallbackFunction widgetTrigger = mock(MonacoStandaloneCodeEditor.CallbackFunction.class);
    final NativeEvent blurEvent = mock(NativeEvent.class);
    when(widget.getElement()).thenReturn(element);
    when(element.getStyle()).thenReturn(style);
    when(domElement.uncheckedCast(any())).thenReturn(mockedElement);
    when(properties.getConstructionOptions()).thenReturn(constructionOptions);
    doReturn(onKeyDown).when(domElement).getOnKeyDown(standaloneCodeEditor);
    doReturn(widgetTrigger).when(domElement).getWidgetTrigger(blurEvent);
    doReturn(blurEvent).when(domElement).getBlurEvent();
    doReturn(properties).when(domElement).makeMonacoPropertiesFactory();
    doReturn(editor).when(domElement).getMonacoEditor();
    doReturn(standaloneCodeEditor).when(editor).create(mockedElement, constructionOptions);
    domElement.setupInternalComponent();
    verify(style).setWidth(100, PCT);
    verify(style).setHeight(100, PCT);
    verify(standaloneCodeEditor).onKeyDown(onKeyDown);
    verify(standaloneCodeEditor).onDidBlurEditorWidget(widgetTrigger);
    verify(widget).setCodeEditor(standaloneCodeEditor);
    verify(widget).setFocus(true);
}
Also used : MonacoEditor(org.uberfire.client.views.pfly.monaco.jsinterop.MonacoEditor) Element(com.google.gwt.user.client.Element) Element(com.google.gwt.user.client.Element) MonacoStandaloneCodeEditor(org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor) MonacoPropertiesFactory(org.kie.workbench.common.dmn.client.widgets.codecompletion.MonacoPropertiesFactory) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Style(com.google.gwt.dom.client.Style) NativeEvent(com.google.gwt.dom.client.NativeEvent) Test(org.junit.Test)

Aggregations

MonacoStandaloneCodeEditor (org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor)7 NativeEvent (com.google.gwt.dom.client.NativeEvent)6 Test (org.junit.Test)6 Style (com.google.gwt.dom.client.Style)2 MonacoPropertiesFactory (org.kie.workbench.common.dmn.client.widgets.codecompletion.MonacoPropertiesFactory)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 Element (com.google.gwt.user.client.Element)1 MonacoEditor (org.uberfire.client.views.pfly.monaco.jsinterop.MonacoEditor)1