diff --git a/include/eepp/scene/inputmethod.hpp b/include/eepp/scene/inputmethod.hpp index 8720e6fe6..156e7016b 100644 --- a/include/eepp/scene/inputmethod.hpp +++ b/include/eepp/scene/inputmethod.hpp @@ -44,6 +44,7 @@ class EE_API InputMethod { SceneNode* mSceneNode{ nullptr }; InputMethod::State mState; bool mEditing{ false }; + Rect mLastLocation; }; }} // namespace EE::Scene diff --git a/projects/macos/ee.files b/projects/macos/ee.files index 73d0021aa..5b57330c1 100644 --- a/projects/macos/ee.files +++ b/projects/macos/ee.files @@ -225,6 +225,7 @@ ../../include/eepp/scene/eventdispatcher.hpp ../../include/eepp/scene/event.hpp ../../include/eepp/scene.hpp +../../include/eepp/scene/inputmethod.hpp ../../include/eepp/scene/keyevent.hpp ../../include/eepp/scene/mouseevent.hpp ../../include/eepp/scene/node.hpp @@ -623,6 +624,7 @@ ../../src/eepp/graphics/vertexbuffervbo.cpp ../../src/eepp/graphics/view.cpp ../../src/eepp/main/eepp_main.cpp +../../src/eepp/scene/inputmethod.cpp ../../src/eepp/ui/doc/languages/angelscript.cpp ../../src/eepp/ui/doc/languages/angelscript.hpp ../../src/eepp/ui/doc/languages/batchscript.cpp diff --git a/src/eepp/scene/eventdispatcher.cpp b/src/eepp/scene/eventdispatcher.cpp index 28be88905..db0a2dc62 100644 --- a/src/eepp/scene/eventdispatcher.cpp +++ b/src/eepp/scene/eventdispatcher.cpp @@ -38,6 +38,8 @@ EventDispatcher::~EventDispatcher() { void EventDispatcher::inputCallback( InputEvent* event ) { switch ( event->Type ) { case InputEvent::Window: { + if ( event->window.type == InputEvent::WindowEventType::WindowKeyboardFocusLost ) + mSceneNode->getIME().stop(); break; } case InputEvent::KeyUp: diff --git a/src/eepp/scene/inputmethod.cpp b/src/eepp/scene/inputmethod.cpp index 0fddf87fa..a2e061809 100644 --- a/src/eepp/scene/inputmethod.cpp +++ b/src/eepp/scene/inputmethod.cpp @@ -7,7 +7,13 @@ namespace EE { namespace Scene { void InputMethod::setLocation( Rect rect ) { - mSceneNode->getWindow()->setTextInputRect( rect ); +#if EE_PLATFORM == EE_PLATFORM_MACOS || EE_PLATFORM == EE_PLATFORM_IOS + rect = PixelDensity::pxToDpI( rect ); +#endif + if ( rect != mLastLocation ) { + mSceneNode->getWindow()->setTextInputRect( rect ); + mLastLocation = std::move( rect ); + } } bool InputMethod::isEditing() const { @@ -56,6 +62,11 @@ void InputMethod::draw( const Vector2f& screenPos, const Float& lineHeight, p.setColor( lineColor ); p.drawRectangle( Rectf( { screenPos.x, screenPos.y + lineHeight - lh * 0.5f }, { width, lh } ) ); + + Float lineOffsetX = + Text::getTextWidth( mState.text.view().substr( 0, mState.start ), fontStyle ); + p.drawRectangle( Rectf( { screenPos.x + lineOffsetX, screenPos.y }, + { PixelDensity::dpToPx( 1.f ), lineHeight } ) ); } if ( drawText ) diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 16f1190ca..ca0ad2ce4 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -898,6 +898,9 @@ Uint32 UICodeEditor::onFocusLoss() { } Uint32 UICodeEditor::onTextInput( const TextInputEvent& event ) { + if ( getUISceneNode()->getIME().isEditing() ) + return 0; + mLastActivity.restart(); if ( mLocked || NULL == mFont ) @@ -924,11 +927,11 @@ Uint32 UICodeEditor::onTextInput( const TextInputEvent& event ) { } void UICodeEditor::updateIMELocation() { - if ( mDoc->getActiveClient() != this ) + if ( mDoc->getActiveClient() != this || !Engine::isRunninMainThread() ) return; updateScreenPos(); - getUISceneNode()->getIME().setLocation( - getScreenPosition( mDoc->getSelection( true ).start() ).asInt() ); + Rectf r( getScreenPosition( mDoc->getSelection( true ).start() ) ); + getUISceneNode()->getIME().setLocation( r.asInt() ); } Uint32 UICodeEditor::onTextEditing( const TextEditingEvent& event ) { @@ -941,6 +944,9 @@ Uint32 UICodeEditor::onTextEditing( const TextEditingEvent& event ) { } Uint32 UICodeEditor::onKeyDown( const KeyEvent& event ) { + if ( getUISceneNode()->getIME().isEditing() ) + return 0; + mLastActivity.restart(); if ( NULL == mFont || mUISceneNode->getUIEventDispatcher()->justGainedFocus() ) diff --git a/src/eepp/ui/uiconsole.cpp b/src/eepp/ui/uiconsole.cpp index cc0600393..b1066557f 100644 --- a/src/eepp/ui/uiconsole.cpp +++ b/src/eepp/ui/uiconsole.cpp @@ -794,6 +794,9 @@ void UIConsole::paste() { } Uint32 UIConsole::onKeyDown( const KeyEvent& event ) { + if ( getUISceneNode()->getIME().isEditing() ) + return 0; + if ( ( event.getKeyCode() == KEY_TAB ) && mDoc.getSelection().start().column() == (Int64)mDoc.getCurrentLine().size() - 1 ) { printCommandsStartingWith( mDoc.getCurrentLine().getTextWithoutNewLine() ); @@ -885,6 +888,9 @@ Uint32 UIConsole::onKeyDown( const KeyEvent& event ) { } Uint32 UIConsole::onTextInput( const TextInputEvent& event ) { + if ( getUISceneNode()->getIME().isEditing() ) + return 0; + Input* input = getUISceneNode()->getWindow()->getInput(); if ( ( input->isLeftAltPressed() && !event.getText().empty() && event.getText()[0] == '\t' ) || diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index 922cec008..54d0a934f 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -767,6 +767,9 @@ void UITextInput::registerKeybindings() { } Uint32 UITextInput::onKeyDown( const KeyEvent& event ) { + if ( getUISceneNode()->getIME().isEditing() ) + return 0; + std::string cmd = mKeyBindings.getCommandFromKeyBind( { event.getKeyCode(), event.getMod() } ); if ( !cmd.empty() ) { // Allow copy selection on locked mode @@ -780,6 +783,9 @@ Uint32 UITextInput::onKeyDown( const KeyEvent& event ) { } Uint32 UITextInput::onTextInput( const TextInputEvent& event ) { + if ( getUISceneNode()->getIME().isEditing() ) + return 0; + if ( !mAllowEditing ) return 0; Input* input = getUISceneNode()->getWindow()->getInput(); @@ -808,7 +814,7 @@ Uint32 UITextInput::onTextInput( const TextInputEvent& event ) { } void UITextInput::updateIMELocation() { - if ( mDoc.getActiveClient() != this ) + if ( mDoc.getActiveClient() != this || !Engine::isRunninMainThread() ) return; updateScreenPos(); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 2c2d6dcd3..92fbe7fa1 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -293,7 +293,7 @@ class App : public UICodeEditorSplitter::Client { mTerminalManager->configureTerminalScrollback(); } ); t.setCommand( "check-for-updates", [this] { checkForUpdates( false ); } ); - t.setCommand( "create-new-window", [this] { + t.setCommand( "create-new-window", [] { std::string processPath = Sys::getProcessFilePath(); if ( !processPath.empty() ) { std::string cmd( processPath + " -x" );