ecode: Quick Fix icon is now clickable. Minor fixes with incorrect usage of setCursor.

This commit is contained in:
Martín Lucas Golini
2024-06-23 22:05:04 -03:00
parent aad3b189d3
commit 4ec00ee02d
6 changed files with 155 additions and 29 deletions

View File

@@ -7,6 +7,7 @@
#include <eepp/system/luapattern.hpp>
#include <eepp/system/scopedop.hpp>
#include <eepp/ui/doc/syntaxdefinitionmanager.hpp>
#include <eepp/ui/uieventdispatcher.hpp>
#include <eepp/ui/uiscenenode.hpp>
#include <nlohmann/json.hpp>
using namespace EE::Graphics;
@@ -1209,8 +1210,11 @@ void AutoCompletePlugin::resetSuggestions( UICodeEditor* editor ) {
mSuggestionsEditor = nullptr;
}
mSuggestions.clear();
if ( editor && editor->hasFocus() )
editor->getUISceneNode()->setCursor( !editor->isLocked() ? Cursor::IBeam : Cursor::Arrow );
if ( editor && editor->hasFocus() ) {
auto mousePos( editor->getUISceneNode()->getUIEventDispatcher()->getMousePosf() );
if ( editor->getScreenRect().contains( mousePos ) )
editor->updateMouseCursor( mousePos );
}
}
void AutoCompletePlugin::resetSignatureHelp() {

View File

@@ -998,6 +998,11 @@ SyntaxStyleType LinterPlugin::getMatchString( const LinterType& type ) {
return "error"_sst;
}
void LinterPlugin::preDraw( UICodeEditor*, const Vector2f& /*startScroll*/,
const Float& /*lineHeight*/, const TextPosition& /*cursor*/ ) {
mQuickFixRect = {};
}
void LinterPlugin::drawAfterLineText( UICodeEditor* editor, const Int64& index, Vector2f position,
const Float& /*fontSize*/, const Float& lineHeight ) {
Lock l( mMatchesMutex );
@@ -1057,24 +1062,30 @@ void LinterPlugin::drawAfterLineText( UICodeEditor* editor, const Int64& index,
Float rLineWidth = 0;
if ( !quickFixRendered && doc->getSelection().start().line() == index &&
!match.diagnostic.codeActions.empty() ) {
rLineWidth = editor->getLineWidth( index ) + editor->getGlyphWidth();
Color wcolor( editor->getColorScheme().getEditorSyntaxStyle( "warning"_sst ).color );
if ( nullptr == mLightbulbIcon ) {
mLightbulbIcon = editor->getUISceneNode()->getUIIconThemeManager()->findIcon(
"lightbulb-autofix" );
}
if ( nullptr != mLightbulbIcon ) {
Drawable* drawable = mLightbulbIcon->getSize( (int)eefloor( lineHeight ) );
if ( drawable == nullptr )
return;
if ( !quickFixRendered && doc->getSelection().start().line() == index ) {
if ( !match.diagnostic.codeActions.empty() ) {
rLineWidth = editor->getLineWidth( index ) + editor->getGlyphWidth();
Color wcolor(
editor->getColorScheme().getEditorSyntaxStyle( "warning"_sst ).color );
if ( nullptr == mLightbulbIcon ) {
mLightbulbIcon = editor->getUISceneNode()->getUIIconThemeManager()->findIcon(
"lightbulb-autofix" );
}
if ( nullptr != mLightbulbIcon ) {
Drawable* drawable = mLightbulbIcon->getSize( (int)eefloor( lineHeight ) );
if ( drawable == nullptr )
return;
Color oldColor( drawable->getColor() );
drawable->setColor( wcolor );
drawable->draw( { position.x + rLineWidth, position.y } );
drawable->setColor( oldColor );
quickFixRendered = true;
Color oldColor( drawable->getColor() );
drawable->setColor( wcolor );
Vector2f pos = { position.x + rLineWidth, position.y };
drawable->draw( pos );
mQuickFixRect = { pos, drawable->getPixelsSize() };
drawable->setColor( oldColor );
quickFixRendered = true;
}
} else {
mQuickFixRect = {};
}
}
@@ -1251,7 +1262,21 @@ void LinterPlugin::goToPrevError( UICodeEditor* editor ) {
}
}
bool LinterPlugin::onMouseClick( UICodeEditor* editor, const Vector2i& pos, const Uint32& flags ) {
if ( ( flags & EE_BUTTON_LMASK ) && mQuickFixRect.Right != 0 && mQuickFixRect.Bottom != 0 &&
mQuickFixRect.contains( pos.asFloat() ) ) {
editor->getDocument().execute( "lsp-symbol-code-action", editor );
return true;
}
return false;
}
bool LinterPlugin::onMouseMove( UICodeEditor* editor, const Vector2i& pos, const Uint32& flags ) {
if ( mQuickFixRect.Right != 0 && mQuickFixRect.Bottom != 0 &&
mQuickFixRect.contains( pos.asFloat() ) ) {
editor->getUISceneNode()->setCursor( Cursor::Hand );
return true;
}
if ( flags != 0 ) {
tryHideHoveringMatch( editor );
return false;

View File

@@ -96,6 +96,8 @@ class LinterPlugin : public Plugin {
bool onMouseLeave( UICodeEditor*, const Vector2i&, const Uint32& );
bool onMouseClick( UICodeEditor*, const Vector2i&, const Uint32& flags );
const Time& getDelayTime() const;
void setDelayTime( const Time& delayTime );
@@ -121,10 +123,12 @@ class LinterPlugin : public Plugin {
void unregisterNativeLinter( const std::string& cmd );
void preDraw( UICodeEditor*, const Vector2f&, const Float&, const TextPosition& );
protected:
std::vector<Linter> mLinters;
std::unordered_map<UICodeEditor*, std::vector<Uint32>> mEditors;
std::set<TextDocument*> mDocs;
std::unordered_set<TextDocument*> mDocs;
std::unordered_map<UICodeEditor*, TextDocument*> mEditorDocs;
std::unordered_map<TextDocument*, std::unique_ptr<Clock>> mDirtyDoc;
std::unordered_map<TextDocument*, std::map<Int64, std::vector<LinterMatch>>> mMatches;
@@ -150,6 +154,7 @@ class LinterPlugin : public Plugin {
String::HashType mConfigHash{ 0 };
UIIcon* mLightbulbIcon{ nullptr };
std::string mErrorMsg;
Rectf mQuickFixRect;
LinterPlugin( PluginManager* pluginManager, bool sync );