IME support macOS improvements.

This commit is contained in:
Martín Lucas Golini
2023-10-29 18:02:17 -03:00
parent a050580fce
commit 28421fd598
8 changed files with 40 additions and 6 deletions

View File

@@ -44,6 +44,7 @@ class EE_API InputMethod {
SceneNode* mSceneNode{ nullptr };
InputMethod::State mState;
bool mEditing{ false };
Rect mLastLocation;
};
}} // namespace EE::Scene

View File

@@ -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

View File

@@ -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:

View File

@@ -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 )

View File

@@ -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() )

View File

@@ -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' ) ||

View File

@@ -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();

View File

@@ -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" );