From 4bc250515ca4d0ee50019d734fe4c0570a647361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 8 Feb 2024 22:23:46 -0300 Subject: [PATCH] UICodeEditor use the default keyboard modifier. Some minor fixes. --- include/eepp/window/input.hpp | 3 +++ src/eepp/scene/node.cpp | 2 +- src/eepp/ui/uicodeeditor.cpp | 18 +++++++++--------- src/eepp/window/input.cpp | 4 ++++ src/tools/ecode/ecode.cpp | 4 ++-- src/tools/ecode/settingsmenu.cpp | 2 +- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/eepp/window/input.hpp b/include/eepp/window/input.hpp index 672f3e5d9..b9e0e9fde 100644 --- a/include/eepp/window/input.hpp +++ b/include/eepp/window/input.hpp @@ -105,6 +105,9 @@ class EE_API Input { /** @return If the Control Key is pressed */ bool isControlPressed() const; + /** @return If the default key modifier is pressed */ + bool isKeyModPressed() const; + /** @return If the left Shift Key is pressed */ bool isLeftShiftPressed() const; diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp index e9b03d65a..28593f8f5 100644 --- a/src/eepp/scene/node.cpp +++ b/src/eepp/scene/node.cpp @@ -1581,7 +1581,7 @@ void Node::debounce( Actions::Runnable::RunnableFunc runnable, const Time& delay action->setCallback( std::move( runnable ) ); action->restart(); } else { - setTimeout( std::move( runnable ), std::move( delay ), uniqueIdentifier ); + setTimeout( std::move( runnable ), delay, uniqueIdentifier ); } } diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 3a373ec48..16a4bd6e7 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -1003,7 +1003,7 @@ Uint32 UICodeEditor::onKeyUp( const KeyEvent& event ) { for ( auto& plugin : mPlugins ) if ( plugin->onKeyUp( this, event ) ) return 1; - if ( mHandShown && !getUISceneNode()->getWindow()->getInput()->isControlPressed() ) + if ( mHandShown && !getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) resetLinkOver(); return UIWidget::onKeyUp( event ); } @@ -1341,14 +1341,14 @@ Uint32 UICodeEditor::onMouseUp( const Vector2i& position, const Uint32& flags ) } if ( flags & EE_BUTTON_WDMASK ) { - if ( getUISceneNode()->getWindow()->getInput()->isControlPressed() ) { + if ( getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) { mDoc->execute( "font-size-shrink" ); } else { setScrollY( mScroll.y + PixelDensity::dpToPx( mMouseWheelScroll ) ); } invalidateDraw(); } else if ( flags & EE_BUTTON_WUMASK ) { - if ( getUISceneNode()->getWindow()->getInput()->isControlPressed() ) { + if ( getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) { mDoc->execute( "font-size-grow" ); } else { setScrollY( mScroll.y - PixelDensity::dpToPx( mMouseWheelScroll ) ); @@ -1378,7 +1378,7 @@ Uint32 UICodeEditor::onMouseClick( const Vector2i& position, const Uint32& flags } if ( ( flags & EE_BUTTON_LMASK ) && - getUISceneNode()->getWindow()->getInput()->isControlPressed() ) { + getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) { String link( checkMouseOverLink( position ) ); if ( !link.empty() ) { Engine::instance()->openURI( link.toUtf8() ); @@ -3425,20 +3425,20 @@ void UICodeEditor::checkMouseOverColor( const Vector2i& position ) { } String UICodeEditor::checkMouseOverLink( const Vector2i& position ) { - if ( !mInteractiveLinks || !getUISceneNode()->getWindow()->getInput()->isControlPressed() ) + if ( !mInteractiveLinks || !getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) return resetLinkOver(); TextPosition pos( resolveScreenPosition( position.asFloat(), false ) ); - if ( mDoc->getChar( pos ) == '\n' ) - return resetLinkOver(); - - if ( pos.line() > (Int64)mDoc->linesCount() ) + if ( pos.line() >= (Int64)mDoc->linesCount() ) return resetLinkOver(); const String& line = mDoc->line( pos.line() ).getText(); if ( pos.column() >= (Int64)line.size() - 1 ) return resetLinkOver(); + if ( mDoc->getChar( pos ) == '\n' ) + return resetLinkOver(); + TextPosition startB( mDoc->previousSpaceBoundaryInLine( pos ) ); TextPosition endB( mDoc->nextSpaceBoundaryInLine( pos ) ); diff --git a/src/eepp/window/input.cpp b/src/eepp/window/input.cpp index 20fa30b25..dedece434 100644 --- a/src/eepp/window/input.cpp +++ b/src/eepp/window/input.cpp @@ -347,6 +347,10 @@ bool Input::isControlPressed() const { return ( mInputMod & KEYMOD_CTRL ) != 0; } +bool Input::isKeyModPressed() const { + return ( mInputMod & KeyMod::getDefaultModifier() ) != 0; +} + bool Input::isLeftShiftPressed() const { return ( mInputMod & KEYMOD_LSHIFT ) != 0; } diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index b57513170..22123f99d 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2868,7 +2868,7 @@ void App::renameFile( const FileInfo& file ) { if ( file.isDirectory() ) FileSystem::dirRemoveSlashAtEnd( fpath ); fsRenameFile( fpath, newFilePath ); - } catch ( const fs::filesystem_error& err ) { + } catch ( const fs::filesystem_error& ) { errorMsgBox( i18n( "error_renaming_file", "Error renaming file." ) ); } msgBox->closeWindow(); @@ -3603,7 +3603,7 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe "fonts/DejaVuSansMonoNerdFontComplete.ttf" ); if ( ( nullptr != mTerminalFont && mTerminalFont->getInfo().family == "DejaVuSansMono NF" && mFontMono->getInfo().family == "DejaVu Sans Mono" ) || - mTerminalFont->getInfo().family == mFontMono->getInfo().family ) { + ( nullptr != mTerminalFont && mTerminalFont->getInfo().family == mFontMono->getInfo().family ) ) { mTerminalFont->setBoldFont( mFontMono->getBoldFont() ); mTerminalFont->setItalicFont( mFontMono->getItalicFont() ); mTerminalFont->setBoldItalicFont( mFontMono->getBoldItalicFont() ); diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index 76f1c6cda..3e7e3b8be 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -1831,7 +1831,7 @@ void SettingsMenu::deleteFileDialog( const FileInfo& file ) { std::string fpath( file.getFilepath() ); FileSystem::dirRemoveSlashAtEnd( fpath ); fsRemoveAll( fpath ); - } catch ( const fs::filesystem_error& err ) { + } catch ( const fs::filesystem_error& ) { errFn(); } } else if ( !FileSystem::fileRemove( file.getFilepath() ) ) {