mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 07:52:45 +00:00 
			
		
		
		
	HackStudio: Always re-match curlies/parens after a re-highlight
While you are typing in HackStudio, we re-lex the C++ as you type, so this means we also need to keep re-checking for matching curlies and parentheses at the cursor. Fixes #769 (although it's not optional, because it's too cool. :^)
This commit is contained in:
		
							parent
							
								
									d5afc58744
								
							
						
					
					
						commit
						15fb341eb4
					
				
					 3 changed files with 24 additions and 10 deletions
				
			
		|  | @ -172,17 +172,8 @@ void Editor::mousemove_event(GMouseEvent& event) | ||||||
|     GApplication::the().hide_tooltip(); |     GApplication::the().hide_tooltip(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Editor::cursor_did_change() | void Editor::highlight_matching_curlies_or_parens() | ||||||
| { | { | ||||||
|     if (m_has_brace_buddies) { |  | ||||||
|         if (m_brace_buddies[0].index >= 0 && m_brace_buddies[0].index < document().spans().size()) |  | ||||||
|             document().set_span_at_index(m_brace_buddies[0].index, m_brace_buddies[0].span_backup); |  | ||||||
|         if (m_brace_buddies[1].index >= 0 && m_brace_buddies[1].index < document().spans().size()) |  | ||||||
|             document().set_span_at_index(m_brace_buddies[1].index, m_brace_buddies[1].span_backup); |  | ||||||
|         m_has_brace_buddies = false; |  | ||||||
|         update(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     enum class Direction { |     enum class Direction { | ||||||
|         Forward, |         Forward, | ||||||
|         Backward, |         Backward, | ||||||
|  | @ -254,3 +245,22 @@ void Editor::cursor_did_change() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void Editor::cursor_did_change() | ||||||
|  | { | ||||||
|  |     if (m_has_brace_buddies) { | ||||||
|  |         if (m_brace_buddies[0].index >= 0 && m_brace_buddies[0].index < document().spans().size()) | ||||||
|  |             document().set_span_at_index(m_brace_buddies[0].index, m_brace_buddies[0].span_backup); | ||||||
|  |         if (m_brace_buddies[1].index >= 0 && m_brace_buddies[1].index < document().spans().size()) | ||||||
|  |             document().set_span_at_index(m_brace_buddies[1].index, m_brace_buddies[1].span_backup); | ||||||
|  |         m_has_brace_buddies = false; | ||||||
|  |         update(); | ||||||
|  |     } | ||||||
|  |     highlight_matching_curlies_or_parens(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Editor::notify_did_rehighlight() | ||||||
|  | { | ||||||
|  |     m_has_brace_buddies = false; | ||||||
|  |     highlight_matching_curlies_or_parens(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -15,6 +15,8 @@ public: | ||||||
|     EditorWrapper& wrapper(); |     EditorWrapper& wrapper(); | ||||||
|     const EditorWrapper& wrapper() const; |     const EditorWrapper& wrapper() const; | ||||||
| 
 | 
 | ||||||
|  |     void notify_did_rehighlight(); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|     virtual void focusin_event(CEvent&) override; |     virtual void focusin_event(CEvent&) override; | ||||||
|     virtual void focusout_event(CEvent&) override; |     virtual void focusout_event(CEvent&) override; | ||||||
|  | @ -23,6 +25,7 @@ private: | ||||||
|     virtual void cursor_did_change() override; |     virtual void cursor_did_change() override; | ||||||
| 
 | 
 | ||||||
|     void show_documentation_tooltip_if_available(const String&, const Point& screen_location); |     void show_documentation_tooltip_if_available(const String&, const Point& screen_location); | ||||||
|  |     void highlight_matching_curlies_or_parens(); | ||||||
| 
 | 
 | ||||||
|     explicit Editor(GWidget* parent); |     explicit Editor(GWidget* parent); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -488,6 +488,7 @@ static void rehighlight() | ||||||
|         spans.append(span); |         spans.append(span); | ||||||
|     } |     } | ||||||
|     current_editor().document().set_spans(spans); |     current_editor().document().set_spans(spans); | ||||||
|  |     static_cast<Editor&>(current_editor()).notify_did_rehighlight(); | ||||||
|     current_editor().update(); |     current_editor().update(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling