mirror of
				https://github.com/chylex/IntelliJ-AceJump.git
				synced 2025-11-04 09:40:10 +01:00 
			
		
		
		
	Compare commits
	
		
			64 Commits
		
	
	
		
			vim
			...
			35003b0bab
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						35003b0bab
	
				 | 
					
					
						|||
| 
						 | 
					dc137e4d23 | ||
| 
						 | 
					6858b745e6 | ||
| 
						 | 
					1505e98d66 | ||
| 
						 | 
					2b7015474e | ||
| 
						 | 
					8d62b0d130 | ||
| 
						
						
							
						
						828940a53a
	
				 | 
					
					
						|||
| 
						
						
							
						
						41071dbaf9
	
				 | 
					
					
						|||
| 
						 | 
					cb10ff7789 | ||
| 
						 | 
					71f8d7150d | ||
| 
						 | 
					e619f5feb0 | ||
| 
						 | 
					9dd85c1815 | ||
| 
						 | 
					194dc3a14e | ||
| 
						 | 
					f1488f7fdf | ||
| 
						 | 
					952a9af9ad | ||
| 
						 | 
					86a7ad751f | ||
| 
						 | 
					650a00f491 | ||
| 
						 | 
					9573315eff | ||
| 
						 | 
					eef4c2e08f | ||
| 
						 | 
					d1277dcb8a | ||
| 
						 | 
					7ef147c941 | ||
| 
						 | 
					4504da02ba | ||
| 
						 | 
					7cce1b7034 | ||
| 
						 | 
					16fd472132 | ||
| 
						 | 
					3c231327d0 | ||
| 
						 | 
					9284514ce3 | ||
| 
						 | 
					767a72a97c | ||
| 
						 | 
					d1ad283c8c | ||
| 
						 | 
					a169e3c751 | ||
| 
						 | 
					0ee9f3e1cb | ||
| 
						 | 
					a05e92f3cb | ||
| 
						
						
							
						
						17a762e4d8
	
				 | 
					
					
						|||
| 
						
						
							
						
						aaa3f5d922
	
				 | 
					
					
						|||
| 
						
						
							
						
						d407fd5333
	
				 | 
					
					
						|||
| 
						
						
							
						
						12ae15c0f7
	
				 | 
					
					
						|||
| 
						 | 
					5fd99c7f9b | ||
| 
						 | 
					d0cd15ef2c | ||
| 
						 | 
					e6184ca6d3 | ||
| 
						 | 
					020b6c1c7c | ||
| 
						 | 
					9839a43da4 | ||
| 
						 | 
					a7ebbcadb4 | ||
| 
						 | 
					4622fbb20b | ||
| 
						 | 
					b3df72ef81 | ||
| 
						 | 
					00ed423faa | ||
| 
						 | 
					615ac0bc7a | ||
| 
						 | 
					2c0a236ed8 | ||
| 
						 | 
					d6553cd358 | ||
| 
						 | 
					5bb9a98723 | ||
| 
						 | 
					85163d4fb9 | ||
| 
						 | 
					02fee84923 | ||
| 
						 | 
					89c3f88fbf | ||
| 
						 | 
					8fe050dc15 | ||
| 
						 | 
					61f0e3cf77 | ||
| 
						 | 
					27b897848d | ||
| 
						 | 
					e17abbdabb | ||
| 
						 | 
					5da53c603e | ||
| 
						 | 
					59e0082236 | ||
| 
						 | 
					d2b1fb96dd | ||
| 
						 | 
					d5dfa95896 | ||
| 
						 | 
					a109ff7fce | ||
| 
						 | 
					b33ae482b0 | ||
| 
						 | 
					c6b70109da | ||
| 
						 | 
					beb39c95c8 | ||
| 
						 | 
					f675efbc12 | 
							
								
								
									
										182
									
								
								CHANGES.md
									
									
									
									
									
								
							
							
						
						
									
										182
									
								
								CHANGES.md
									
									
									
									
									
								
							@@ -1,233 +1,271 @@
 | 
				
			|||||||
# Changelog
 | 
					# Changelog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.7
 | 
					## Unreleased
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 3.8.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Restores <kbd>Tab</kbd>/<kbd>Shift</kbd>+<kbd>Tab</kbd> functionality, [#356](https://github.com/acejump/AceJump/issues/356)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 3.8.4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Fixes Declaration Mode in Rider, [#379](https://github.com/acejump/AceJump/issues/379), thanks to @igor-akhmetov for helping diagnose!
 | 
				
			||||||
 | 
					- Fixes highlight offset on high-DPI screens, [#362](https://github.com/acejump/AceJump/issues/362), thanks to @chylex for [the PR](https://github.com/acejump/AceJump/pull/384)!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 3.8.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Displays regular expression for regex-based queries
 | 
				
			||||||
 | 
					- Fixes a bug when current search text was enabled causing word and line mode tags to not be displayed, [#376](https://github.com/acejump/AceJump/issues/376)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 3.8.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Add option to display current search text, [#375](https://github.com/acejump/AceJump/issues/375)
 | 
				
			||||||
 | 
					- Fixes a bug where editor was not focused, [#374](https://github.com/acejump/AceJump/issues/374)
 | 
				
			||||||
 | 
					- Thanks to @SaiKai for the PRs!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 3.8.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Hotfix for stale cache, [#373](https://github.com/acejump/AceJump/issues/373)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 3.8.0
 | 
				
			||||||
 | 
					- Allow jumping between splitters in the editor, [#371](https://github.com/acejump/AceJump/pull/371)
 | 
				
			||||||
 | 
					- Adds support for unicode search and selection, [#368](https://github.com/acejump/AceJump/issues/368)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 3.7.1
 | 
				
			||||||
 | 
					- Fix settings display issue, [#363](https://github.com/acejump/AceJump/issues/363)
 | 
				
			||||||
 | 
					- Update AceJump extension API to include tag information, [#357](https://github.com/acejump/AceJump/pull/357)
 | 
				
			||||||
 | 
					- Allow defining jump mode with boundaries, [#358](https://github.com/acejump/AceJump/pull/358)
 | 
				
			||||||
 | 
					- Use Kotlin classes for actions, [#359](https://github.com/acejump/AceJump/pull/359)
 | 
				
			||||||
 | 
					- Thanks to @AlexPl292 for the PRs!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 3.7.0
 | 
				
			||||||
- Improvements to tag latency
 | 
					- Improvements to tag latency
 | 
				
			||||||
- Redesign settings panel
 | 
					- Redesign settings panel
 | 
				
			||||||
  - Add missing configuration for definition mode color
 | 
					  - Add missing configuration for definition mode color
 | 
				
			||||||
  - Adds option to switch between straight and rounded tag corners
 | 
					  - Adds option to switch between straight and rounded tag corners
 | 
				
			||||||
  - Adds option to only consider visible area
 | 
					  - Adds option to only consider visible area
 | 
				
			||||||
  - Add customizable jump mode cycling 
 | 
					  - Add customizable jump mode cycling
 | 
				
			||||||
- Jump-to-End mode jumps to the end of a word
 | 
					- Jump-to-End mode jumps to the end of a word
 | 
				
			||||||
- Fixes toggle keys not resetting mode when pressed twice
 | 
					- Fixes toggle keys not resetting mode when pressed twice
 | 
				
			||||||
- Increase limit for what is considered a large file
 | 
					- Increase limit for what is considered a large file
 | 
				
			||||||
- Thanks to @chylex for [all the PRs](https://github.com/acejump/AceJump/pulls?q=is%3Apr+author%3Achylex)!
 | 
					- Major refactoring, [#350](https://github.com/acejump/AceJump/pull/353)
 | 
				
			||||||
 | 
					- [Many bug fixes](https://github.com/acejump/AceJump/issues/348#issuecomment-739454920): [#338](https://github.com/acejump/AceJump/issues/338), [#336](https://github.com/acejump/AceJump/issues/336), [#329](https://github.com/acejump/AceJump/issues/329), [#327](https://github.com/acejump/AceJump/issues/327), [#310](https://github.com/acejump/AceJump/issues/310), [#233](https://github.com/acejump/AceJump/issues/233), [#228](https://github.com/acejump/AceJump/issues/228), [#187](https://github.com/acejump/AceJump/issues/187), [#147](https://github.com/acejump/AceJump/issues/147), [#132](https://github.com/acejump/AceJump/issues/132), [#71](https://github.com/acejump/AceJump/issues/71)
 | 
				
			||||||
 | 
					- Huge thanks to @chylex for [all the PRs](https://github.com/acejump/AceJump/pulls?q=is%3Apr+author%3Achylex)!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.6.3
 | 
					## 3.6.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Vote for your favorite <a href="https://twitter.com/breandan/status/1274169810411274241">AceJump logo</a>!
 | 
					- Vote for your favorite <a href="https://twitter.com/breandan/status/1274169810411274241">AceJump logo</a>!
 | 
				
			||||||
- Fixes potential bug.
 | 
					- Fixes potential bug.
 | 
				
			||||||
- Increases test coverage.
 | 
					- Increases test coverage.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.6.2
 | 
					## 3.6.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes [#226](https://github.com/acejump/AceJump/issues/226). Thanks @AlexPl292!
 | 
					- Fixes [#226](https://github.com/acejump/AceJump/issues/226). Thanks @AlexPl292!
 | 
				
			||||||
- Update Pinyin engine.
 | 
					- Update Pinyin engine.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.6.1
 | 
					## 3.6.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes [#324](https://github.com/acejump/AceJump/issues/324). Thanks @AlexPl292!
 | 
					- Fixes [#324](https://github.com/acejump/AceJump/issues/324). Thanks @AlexPl292!
 | 
				
			||||||
- Fixes [#325](https://github.com/acejump/AceJump/issues/325).
 | 
					- Fixes [#325](https://github.com/acejump/AceJump/issues/325).
 | 
				
			||||||
- Fixes Pinyin support.
 | 
					- Fixes Pinyin support.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.6.0
 | 
					## 3.6.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Adds support for Chinese [#314](https://github.com/acejump/AceJump/issues/314).
 | 
					- Adds support for Chinese [#314](https://github.com/acejump/AceJump/issues/314).
 | 
				
			||||||
- Fixes constantly loading settings page [#303](https://github.com/acejump/AceJump/issues/303).
 | 
					- Fixes constantly loading settings page [#303](https://github.com/acejump/AceJump/issues/303).
 | 
				
			||||||
- Honor camel humps [#315](https://github.com/acejump/AceJump/issues/315). Thanks to @clojj.
 | 
					- Honor camel humps [#315](https://github.com/acejump/AceJump/issues/315). Thanks to @clojj.
 | 
				
			||||||
- Support dynamic application reloading [#322](https://github.com/acejump/AceJump/issues/322).
 | 
					- Support dynamic application reloading [#322](https://github.com/acejump/AceJump/issues/322).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.5.9
 | 
					## 3.5.9
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fix a build configuration error affecting plugins which depend on AceJump. Fixes [#305](https://github.com/acejump/AceJump/issues/305).
 | 
					- Fix a build configuration error affecting plugins which depend on AceJump. Fixes [#305](https://github.com/acejump/AceJump/issues/305).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.5.8
 | 
					## 3.5.8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Tagging improvements
 | 
					- Tagging improvements
 | 
				
			||||||
- Support for external plugin integration
 | 
					- Support for external plugin integration
 | 
				
			||||||
- Fixes [#304](https://github.com/acejump/AceJump/issues/304), [#255](https://github.com/acejump/AceJump/issues/255)
 | 
					- Fixes [#304](https://github.com/acejump/AceJump/issues/304), [#255](https://github.com/acejump/AceJump/issues/255)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.5.7
 | 
					## 3.5.7
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- <kbd>Tab</kbd>/<kbd>Enter</kbd> will now scroll horizontally if results are not visible.
 | 
					- <kbd>Tab</kbd>/<kbd>Enter</kbd> will now scroll horizontally if results are not visible.
 | 
				
			||||||
- Fixes [#294](https://github.com/acejump/AceJump/issues/294) "Access is allowed from event dispatch thread only" error
 | 
					- Fixes [#294](https://github.com/acejump/AceJump/issues/294) "Access is allowed from event dispatch thread only" error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.5.6
 | 
					## 3.5.6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Key prioritization for most common keyboard layouts and fixes for a number of minor issues.
 | 
					- Key prioritization for most common keyboard layouts and fixes for a number of minor issues.
 | 
				
			||||||
- Fixes: Index OOB [#242](https://github.com/acejump/AceJump/issues/242), Missing editor [#249](https://github.com/acejump/AceJump/issues/249), [#275](https://github.com/acejump/AceJump/issues/275), Forgotten block caret [#278](https://github.com/acejump/AceJump/issues/278), QWERTZ layout [#273](https://github.com/acejump/AceJump/issues/273)
 | 
					- Fixes: Index OOB [#242](https://github.com/acejump/AceJump/issues/242), Missing editor [#249](https://github.com/acejump/AceJump/issues/249), [#275](https://github.com/acejump/AceJump/issues/275), Forgotten block caret [#278](https://github.com/acejump/AceJump/issues/278), QWERTZ layout [#273](https://github.com/acejump/AceJump/issues/273)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.5.5
 | 
					## 3.5.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- <kbd>Enter</kbd> will now escape exit from AceJump when there is a single visible tag. [#274](https://github.com/acejump/AceJump/issues/274)
 | 
					- <kbd>Enter</kbd> will now escape exit from AceJump when there is a single visible tag. [#274](https://github.com/acejump/AceJump/issues/274)
 | 
				
			||||||
- <kbd>Shift</kbd>+<kbd>Tab</kbd> to scroll to previous occurrences now works properly. [#179](https://github.com/acejump/AceJump/issues/179)
 | 
					- <kbd>Shift</kbd>+<kbd>Tab</kbd> to scroll to previous occurrences now works properly. [#179](https://github.com/acejump/AceJump/issues/179)
 | 
				
			||||||
- Fixes an error with sticky block caret mode. [#269](https://github.com/acejump/AceJump/issues/269)
 | 
					- Fixes an error with sticky block caret mode. [#269](https://github.com/acejump/AceJump/issues/269)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.5.4
 | 
					## 3.5.4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Introduces cyclical selection: press Enter or Shift + Enter to cycle through tags on the screen. Press Escape to return to the editor.
 | 
					- Introduces cyclical selection: press Enter or Shift + Enter to cycle through tags on the screen. Press Escape to return to the editor.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.5.3
 | 
					## 3.5.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes for two regressions affecting caret color and shift-selection.
 | 
					- Fixes for two regressions affecting caret color and shift-selection.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.5.2
 | 
					## 3.5.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Various improvements to settings page, including a keyboard layout selector.
 | 
					- Various improvements to settings page, including a keyboard layout selector.
 | 
				
			||||||
- Shorter tags on average, AceJump tries to use a single-character tag more often.
 | 
					- Shorter tags on average, AceJump tries to use a single-character tag more often.
 | 
				
			||||||
- Tag characters are now prioritized by user-defined order from the settings page.
 | 
					- Tag characters are now prioritized by user-defined order from the settings page.
 | 
				
			||||||
- Fixes an issue when running the plugin on platform version 2018.3 and above.
 | 
					- Fixes an issue when running the plugin on platform version 2018.3 and above.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.5.1
 | 
					## 3.5.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Now supports searching for CaPiTaLiZeD letters (typing capital letters in the query will force a case-sensitive search).
 | 
					- Now supports searching for CaPiTaLiZeD letters (typing capital letters in the query will force a case-sensitive search).
 | 
				
			||||||
- **Declaration Mode**: Press the AceJump shortcut a second time to activate Declaration Mode, which will jump to the declaration of a variable in the editor.
 | 
					- **Declaration Mode**: Press the AceJump shortcut a second time to activate Declaration Mode, which will jump to the declaration of a variable in the editor.
 | 
				
			||||||
- Keep hitting the AceJump shortcut to cycle between modes (default, declaration, target, disabled).
 | 
					- Keep hitting the AceJump shortcut to cycle between modes (default, declaration, target, disabled).
 | 
				
			||||||
- Bug fix: AceJump settings should now properly persist after restarting the IDE.
 | 
					- Bug fix: AceJump settings should now properly persist after restarting the IDE.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.5.0
 | 
					## 3.5.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Adds two new features. "**Word-Mode**" and quick tag selection.
 | 
					- Adds two new features. "**Word-Mode**" and quick tag selection.
 | 
				
			||||||
- **Word Mode** removes search and addresses latency issues raised in [#161](https://github.com/acejump/AceJump/issues/161). To learn more about **Word Mode**, see the [readme](https://github.com/johnlindquist/AceJump#tips).
 | 
					- **Word Mode** removes search and addresses latency issues raised in [#161](https://github.com/acejump/AceJump/issues/161). To learn more about **Word Mode**, see the [readme](https://github.com/johnlindquist/AceJump#tips).
 | 
				
			||||||
- Pressing <kbd>Enter</kbd> during a search will jump to the next visible match (or closest match, if next is not visible), as per [#133](https://github.com/acejump/AceJump/issues/133).
 | 
					- Pressing <kbd>Enter</kbd> during a search will jump to the next visible match (or closest match, if next is not visible), as per [#133](https://github.com/acejump/AceJump/issues/133).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.4.3
 | 
					## 3.4.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Stability improvements and tagging optimizations. Fixes [#206](https://github.com/acejump/AceJump/issues/206), [#202](https://github.com/acejump/AceJump/issues/202).
 | 
					- Stability improvements and tagging optimizations. Fixes [#206](https://github.com/acejump/AceJump/issues/206), [#202](https://github.com/acejump/AceJump/issues/202).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.4.2
 | 
					## 3.4.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes [a regression](https://github.com/johnlindquist/AceJump/issues/197) affecting older platform versions.
 | 
					- Fixes [a regression](https://github.com/johnlindquist/AceJump/issues/197) affecting older platform versions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.4.1
 | 
					## 3.4.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes a regression affecting tag alignment when line spacing is greater than 1.0. Minor speed improvements.
 | 
					- Fixes a regression affecting tag alignment when line spacing is greater than 1.0. Minor speed improvements.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.4.0
 | 
					## 3.4.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Restores original scroll position if tab search cancelled. Minor improvements to latency and tag painting.
 | 
					- Restores original scroll position if tab search cancelled. Minor improvements to latency and tag painting.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.3.6
 | 
					## 3.3.6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fix for [#129](https://github.com/acejump/AceJump/issues/129).
 | 
					- Fix for [#129](https://github.com/acejump/AceJump/issues/129).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.3.5
 | 
					## 3.3.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Minor bugfix release. Improve handling of window resizing.
 | 
					- Minor bugfix release. Improve handling of window resizing.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.3.4
 | 
					## 3.3.4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Add a settings page. (Settings > Tools > AceJump)
 | 
					- Add a settings page. (Settings > Tools > AceJump)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.3.3
 | 
					## 3.3.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Improve latency and fix a bug in line selection mode.
 | 
					- Improve latency and fix a bug in line selection mode.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.3.2
 | 
					## 3.3.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- AceJump now persists target mode state when scrolling or tabbing.
 | 
					- AceJump now persists target mode state when scrolling or tabbing.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.3.1
 | 
					## 3.3.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes a minor regression where tags are not displaying correctly.
 | 
					- Fixes a minor regression where tags are not displaying correctly.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.3.0
 | 
					## 3.3.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- AceJump now searches the entire document. Press TAB to get the next set of results!
 | 
					- AceJump now searches the entire document. Press TAB to get the next set of results!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.2.7
 | 
					## 3.2.7
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Minor fixes and stability improvements.
 | 
					- Minor fixes and stability improvements.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.2.6
 | 
					## 3.2.6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes an error affecting older versions of the IntelliJ Platform.
 | 
					- Fixes an error affecting older versions of the IntelliJ Platform.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.2.5
 | 
					## 3.2.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- AceJump 3 now supports older IntelliJ Platform and Kotlin versions.
 | 
					- AceJump 3 now supports older IntelliJ Platform and Kotlin versions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.2.4
 | 
					## 3.2.4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Tagging improvements (tags now shorter on average) and visual updates.
 | 
					- Tagging improvements (tags now shorter on average) and visual updates.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.2.3
 | 
					## 3.2.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes a critical issue affecting users with multiple editor windows open.
 | 
					- Fixes a critical issue affecting users with multiple editor windows open.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.2.2
 | 
					## 3.2.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Adds scrolling support and fixes some line spacing issues.
 | 
					- Adds scrolling support and fixes some line spacing issues.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.2.1
 | 
					## 3.2.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- AceJump now synchronizes font style changes in real-time.
 | 
					- AceJump now synchronizes font style changes in real-time.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.2.0
 | 
					## 3.2.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Support Back/Forward navigation in the IntelliJ Platform.
 | 
					- Support Back/Forward navigation in the IntelliJ Platform.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.1.8
 | 
					## 3.1.8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes some errors that occur when the user closes an editor prematurely.
 | 
					- Fixes some errors that occur when the user closes an editor prematurely.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.1.6
 | 
					## 3.1.6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes a rare tag collision scenario and UninitializedPropertyAccess exception
 | 
					- Fixes a rare tag collision scenario and UninitializedPropertyAccess exception
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.1.5
 | 
					## 3.1.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Allow users to enter target mode directly by pressing Ctrl+Alt+;
 | 
					- Allow users to enter target mode directly by pressing Ctrl+Alt+;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.1.4
 | 
					## 3.1.4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes the "Assertion Failed" exception popup
 | 
					- Fixes the "Assertion Failed" exception popup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.1.3
 | 
					## 3.1.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes an error affecting some users during startup.
 | 
					- Fixes an error affecting some users during startup.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.1.2
 | 
					## 3.1.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes an Android Studio regression.
 | 
					- Fixes an Android Studio regression.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.1.1
 | 
					## 3.1.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Hotfix for broken target mode.
 | 
					- Hotfix for broken target mode.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.1.0
 | 
					## 3.1.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Removes the search box, lots of small usability improvements.
 | 
					- Removes the search box, lots of small usability improvements.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.0.7
 | 
					## 3.0.7
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- No longer tags "folded" regions and minor alignment adjustments.
 | 
					- No longer tags "folded" regions and minor alignment adjustments.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.0.6
 | 
					## 3.0.6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes alignment issues, removes top and bottom alignments until there is a better way to visually differentiate adjacent tags.
 | 
					- Fixes alignment issues, removes top and bottom alignments until there is a better way to visually differentiate adjacent tags.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.0.5
 | 
					## 3.0.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Hotfix for target mode.
 | 
					- Hotfix for target mode.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.0.4
 | 
					## 3.0.4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Adds *Line Mode* - press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>;</kbd> to activate.
 | 
					- Adds *Line Mode* - press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>;</kbd> to activate.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.0.3
 | 
					## 3.0.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Updates to tag placement and performance improvements.
 | 
					- Updates to tag placement and performance improvements.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.0.2
 | 
					## 3.0.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes target mode and default shortcut activation for Mac users.
 | 
					- Fixes target mode and default shortcut activation for Mac users.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.0.1
 | 
					## 3.0.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixes target-mode issues affecting users with non-default shortcuts and adds support for Home/End.
 | 
					- Fixes target-mode issues affecting users with non-default shortcuts and adds support for Home/End.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3.0.0
 | 
					## 3.0.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Major rewrite of AceJump. Introducing:
 | 
					- Major rewrite of AceJump. Introducing:
 | 
				
			||||||
    * Realtime search: Just type the word where you want to jump and AceJump will do the rest.
 | 
					    * Realtime search: Just type the word where you want to jump and AceJump will do the rest.
 | 
				
			||||||
@@ -235,82 +273,82 @@
 | 
				
			|||||||
    * Keyboard-aware tagging: Tries to minimize finger travel distance on QWERTY keyboards.
 | 
					    * Keyboard-aware tagging: Tries to minimize finger travel distance on QWERTY keyboards.
 | 
				
			||||||
    * Colorful highlighting: AceJump will now highlight the editor text, as you type.
 | 
					    * Colorful highlighting: AceJump will now highlight the editor text, as you type.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.13
 | 
					## 2.0.13
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fix a regression affecting *Target Mode* and line-based navigation.
 | 
					- Fix a regression affecting *Target Mode* and line-based navigation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.12
 | 
					## 2.0.12
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fix ClassCastException when input letter not present: [#73](https://github.com/acejump/AceJump/issues/73)
 | 
					- Fix ClassCastException when input letter not present: [#73](https://github.com/acejump/AceJump/issues/73)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.11
 | 
					## 2.0.11
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- One hundred percent all natural Kotlin.
 | 
					- One hundred percent all natural Kotlin.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.10
 | 
					## 2.0.10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Support 2016.2, remove upper version limit, update internal Kotlin version
 | 
					- Support 2016.2, remove upper version limit, update internal Kotlin version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.9
 | 
					## 2.0.9
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Compile on Java 7 to address: [#61](https://github.com/acejump/AceJump/issues/61)
 | 
					- Compile on Java 7 to address: [#61](https://github.com/acejump/AceJump/issues/61)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.8
 | 
					## 2.0.8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Compile on Java 6 to address: [#59](https://github.com/acejump/AceJump/issues/59)
 | 
					- Compile on Java 6 to address: [#59](https://github.com/acejump/AceJump/issues/59)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.7
 | 
					## 2.0.7
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Language update for Kotlin 1.0 release.
 | 
					- Language update for Kotlin 1.0 release.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.6
 | 
					## 2.0.6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixing "lost focus" bugs mentioned here: [#41](https://github.com/acejump/AceJump/issues/41)
 | 
					- Fixing "lost focus" bugs mentioned here: [#41](https://github.com/acejump/AceJump/issues/41)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.5
 | 
					## 2.0.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixing "backspace" bugs mentioned here: [#20](https://github.com/acejump/AceJump/issues/20)
 | 
					- Fixing "backspace" bugs mentioned here: [#20](https://github.com/acejump/AceJump/issues/20)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.4
 | 
					## 2.0.4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixing "code folding" bugs mentioned here: [#24](https://github.com/acejump/AceJump/issues/24)
 | 
					- Fixing "code folding" bugs mentioned here: [#24](https://github.com/acejump/AceJump/issues/24)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.3
 | 
					## 2.0.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- More work on Ubuntu focus bug
 | 
					- More work on Ubuntu focus bug
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.2
 | 
					## 2.0.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixed bug when there's only 1 search result
 | 
					- Fixed bug when there's only 1 search result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.1
 | 
					## 2.0.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixing Ubuntu focus bug
 | 
					- Fixing Ubuntu focus bug
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2.0.0
 | 
					## 2.0.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Major release: Added "target mode", many speed increases, multi-char search implemented
 | 
					- Major release: Added "target mode", many speed increases, multi-char search implemented
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 1.1.0
 | 
					## 1.1.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Switching to Kotlin for the code base
 | 
					- Switching to Kotlin for the code base
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 1.0.4
 | 
					## 1.0.4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixing [#9](https://github.com/acejump/AceJump/issues/9) and [#6](https://github.com/acejump/AceJump/issues/6)
 | 
					- Fixing [#9](https://github.com/acejump/AceJump/issues/9) and [#6](https://github.com/acejump/AceJump/issues/6)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 1.0.3
 | 
					## 1.0.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixed minor visual lag when removing the "jumpers" from the editor
 | 
					- Fixed minor visual lag when removing the "jumpers" from the editor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 1.0.2
 | 
					## 1.0.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Cleaning up minor bugs (npe when editor not in focus, not removing layers)
 | 
					- Cleaning up minor bugs (npe when editor not in focus, not removing layers)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 1.0.1
 | 
					## 1.0.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Adding a new jump: "Enter" will take you to the first non-whitespace char in a new line (compare to "Home" which takes you to a new line)
 | 
					- Adding a new jump: "Enter" will take you to the first non-whitespace char in a new line (compare to "Home" which takes you to a new line)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 1.0.0
 | 
					## 1.0.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Cleaned up code base for release
 | 
					- Cleaned up code base for release
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										56
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								README.md
									
									
									
									
									
								
							@@ -28,7 +28,7 @@ AceJump search is [smart case](http://ideavim.sourceforge.net/vim/usr_27.html#vi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## Tips
 | 
					## Tips
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Press <kbd>Tab</kbd> when searching to jump to the next group of matches in the editor.
 | 
					- Press <kbd>Tab</kbd> when searching to jump to the next group of matches in the editor. *This feature is unavailable in `3.6.4-3.8.4`.*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- If you make a mistake searching, just press <kbd>Backspace</kbd> to restart from scratch.
 | 
					- If you make a mistake searching, just press <kbd>Backspace</kbd> to restart from scratch.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -91,21 +91,56 @@ The build artifact will be placed in `build/distributions/`.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
*Miscellaneous: AceJump is built using [Gradle](https://gradle.com/) with the [Gradle Kotlin DSL](https://docs.gradle.org/5.1/userguide/kotlin_dsl.html) and the [gradle-intellij-plugin](https://github.com/JetBrains/gradle-intellij-plugin).*
 | 
					*Miscellaneous: AceJump is built using [Gradle](https://gradle.com/) with the [Gradle Kotlin DSL](https://docs.gradle.org/5.1/userguide/kotlin_dsl.html) and the [gradle-intellij-plugin](https://github.com/JetBrains/gradle-intellij-plugin).*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Extending
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AceJump can be used by other [IntelliJ Platform](https://plugins.jetbrains.com/docs/intellij/welcome.html) plugins. To do so, add the following snippet to your `build.gradle.kts` file:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```kotlin
 | 
				
			||||||
 | 
					intellij {
 | 
				
			||||||
 | 
					  plugins.set("AceJump:<LATEST_VERSION>")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Callers who pass an instance of [`Editor`](https://github.com/JetBrains/intellij-community/blob/master/platform/editor-ui-api/src/com/intellij/openapi/editor/Editor.java) into `SessionManager.start(editor)` will receive a [`Session`](src/main/kotlin/org/acejump/session/Session.kt) instance in return. Sessions are disposed after use.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To use AceJump externally, please see the following example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```kotlin
 | 
				
			||||||
 | 
					import org.acejump.session.SessionManager
 | 
				
			||||||
 | 
					import org.acejump.session.AceJumpListener
 | 
				
			||||||
 | 
					import org.acejump.boundaries.StandardBoundaries.*
 | 
				
			||||||
 | 
					import org.acejump.search.Pattern.*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					val aceJumpSession = SessionManager.start(editorInstance)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					aceJumpSession.addAceJumpListener(object: AceJumpListener {
 | 
				
			||||||
 | 
					  override fun finished() {
 | 
				
			||||||
 | 
					    // ...
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Sessions provide these endpoints for external consumers:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*1.*/ aceJumpSession.markResults(sortedSetOf(/*...*/)) // Pass a set of offsets
 | 
				
			||||||
 | 
					/*2.*/ aceJumpSession.startRegexSearch("[aeiou]+", WHOLE_FILE) // Search for regex
 | 
				
			||||||
 | 
					/*3.*/ aceJumpSession.startRegexSearch(ALL_WORDS, VISIBLE_ON_SCREEN) // Search for Pattern
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Custom boundaries for search (i.e. current line before caret etc.) can also be defined using the [Boundaries](src/main/kotlin/org/acejump/boundaries/Boundaries.kt) interface.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Contributing
 | 
					## Contributing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AceJump is supported by community members like you. Contributions are highly welcome!
 | 
					AceJump is supported by community members like you. Contributions are highly welcome!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
If you would like to [contribute](https://github.com/acejump/AceJump/pulls), here are a few of the ways you can help improve AceJump:
 | 
					If you would like to [contribute](https://github.com/acejump/AceJump/pulls?q=is%3Apr), here are a few of the ways you can help improve AceJump:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* [Improve test coverage](https://github.com/acejump/AceJump/issues/139)
 | 
					* [Improve test coverage](https://github.com/acejump/AceJump/issues/139)
 | 
				
			||||||
* [Add option to place the caret after the search text](https://github.com/acejump/AceJump/issues/225)
 | 
					* [Add action to repeat last search](https://github.com/acejump/AceJump/issues/316)
 | 
				
			||||||
* [Support user-configurable keyboard layouts](https://github.com/acejump/AceJump/issues/172)
 | 
					* [Add configurable RegEx modes](https://github.com/acejump/AceJump/issues/215)
 | 
				
			||||||
* [Speed up tagging on large files](https://github.com/acejump/AceJump/issues/217)
 | 
					* [Add font family and size options](https://github.com/acejump/AceJump/issues/192)
 | 
				
			||||||
 | 
					* [Tag placement and visibility improvements](https://github.com/acejump/AceJump/issues/323)
 | 
				
			||||||
* [Animated documentation](https://github.com/acejump/AceJump/issues/145)
 | 
					* [Animated documentation](https://github.com/acejump/AceJump/issues/145)
 | 
				
			||||||
* [Display current search text](https://github.com/acejump/AceJump/issues/227)
 | 
					 | 
				
			||||||
* [Support for full screen tagging](https://github.com/acejump/AceJump/issues/144)
 | 
					 | 
				
			||||||
* [Fold text between matches](https://github.com/acejump/AceJump/issues/255)
 | 
					* [Fold text between matches](https://github.com/acejump/AceJump/issues/255)
 | 
				
			||||||
* [Multi-platform support](https://github.com/acejump/AceJump/issues/229)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
To start [IntelliJ IDEA CE](https://github.com/JetBrains/intellij-community) with AceJump installed, run `./gradlew runIde -PluginDev [-x test]`.
 | 
					To start [IntelliJ IDEA CE](https://github.com/JetBrains/intellij-community) with AceJump installed, run `./gradlew runIde -PluginDev [-x test]`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -128,7 +163,7 @@ AceJump is inspired by prior work, but adds several improvements, including:
 | 
				
			|||||||
* **Line Mode**: Jump to the first, last, or first non-whitespace character of any line on-screen (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>;</kbd>).
 | 
					* **Line Mode**: Jump to the first, last, or first non-whitespace character of any line on-screen (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>;</kbd>).
 | 
				
			||||||
* **Word Mode**: Jump to the first character of any visible word on-screen in two keystrokes or less.
 | 
					* **Word Mode**: Jump to the first character of any visible word on-screen in two keystrokes or less.
 | 
				
			||||||
* **Declaration Mode**: Jump to the declaration of a token (if it is available) rather than the token itself.
 | 
					* **Declaration Mode**: Jump to the declaration of a token (if it is available) rather than the token itself.
 | 
				
			||||||
* **Pinyin support**: Pinyin search and selection, e.g. to search for "拼音", activate AceJump and type: <kbd>p</kbd><kbd>y</kbd>
 | 
					* **Unicode support**: Unicode search and selection, e.g. to search for "拼音", activate AceJump and type: <kbd>p</kbd><kbd>y</kbd>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The following plugins have a similar UI for navigating text and web browsing:
 | 
					The following plugins have a similar UI for navigating text and web browsing:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -143,6 +178,7 @@ The following plugins have a similar UI for navigating text and web browsing:
 | 
				
			|||||||
| [ace-jump-mode](https://github.com/winterTTr/ace-jump-mode)           |                           [⬇](https://melpa.org/#/ace-jump-mode)                            |                      [emacs](https://www.gnu.org/software/emacs/)                      |         :x:         |    [Emacs Lisp](https://www.gnu.org/software/emacs/manual/eintr.html)    |
 | 
					| [ace-jump-mode](https://github.com/winterTTr/ace-jump-mode)           |                           [⬇](https://melpa.org/#/ace-jump-mode)                            |                      [emacs](https://www.gnu.org/software/emacs/)                      |         :x:         |    [Emacs Lisp](https://www.gnu.org/software/emacs/manual/eintr.html)    |
 | 
				
			||||||
| [avy](https://github.com/abo-abo/avy)                                 |                                [⬇](https://melpa.org/#/avy)                                 |                      [emacs](https://www.gnu.org/software/emacs/)                      | :heavy_check_mark:  |    [Emacs Lisp](https://www.gnu.org/software/emacs/manual/eintr.html)    |
 | 
					| [avy](https://github.com/abo-abo/avy)                                 |                                [⬇](https://melpa.org/#/avy)                                 |                      [emacs](https://www.gnu.org/software/emacs/)                      | :heavy_check_mark:  |    [Emacs Lisp](https://www.gnu.org/software/emacs/manual/eintr.html)    |
 | 
				
			||||||
| [EasyMotion](https://github.com/easymotion/vim-easymotion)            |                        [⬇](https://vimawesome.com/plugin/easymotion)                        |                               [Vim](http://www.vim.org/)                               |         :x:         |       [Vimscript](http://learnvimscriptthehardway.stevelosh.com/)        |
 | 
					| [EasyMotion](https://github.com/easymotion/vim-easymotion)            |                        [⬇](https://vimawesome.com/plugin/easymotion)                        |                               [Vim](http://www.vim.org/)                               |         :x:         |       [Vimscript](http://learnvimscriptthehardway.stevelosh.com/)        |
 | 
				
			||||||
 | 
					| [Hop](https://github.com/phaazon/hop.nvim)                            |                        [⬇](https://github.com/phaazon/hop.nvim#installation)                |                               [NeoVim](https://neovim.io/)                             |  :heavy_check_mark: |                       [Lua](https://www.lua.org/)                        |
 | 
				
			||||||
| [Sublime EasyMotion](https://github.com/tednaleid/sublime-EasyMotion) |                     [⬇](https://packagecontrol.io/packages/EasyMotion)                      |                        [Sublime](https://www.sublimetext.com/)                         |         :x:         |                    [Python](https://www.python.org/)                     |
 | 
					| [Sublime EasyMotion](https://github.com/tednaleid/sublime-EasyMotion) |                     [⬇](https://packagecontrol.io/packages/EasyMotion)                      |                        [Sublime](https://www.sublimetext.com/)                         |         :x:         |                    [Python](https://www.python.org/)                     |
 | 
				
			||||||
| [AceJump](https://github.com/ice9js/ace-jump-sublime)                 |                       [⬇](https://packagecontrol.io/packages/AceJump)                       |                        [Sublime](https://www.sublimetext.com/)                         | :heavy_check_mark:  |                    [Python](https://www.python.org/)                     |
 | 
					| [AceJump](https://github.com/ice9js/ace-jump-sublime)                 |                       [⬇](https://packagecontrol.io/packages/AceJump)                       |                        [Sublime](https://www.sublimetext.com/)                         | :heavy_check_mark:  |                    [Python](https://www.python.org/)                     |
 | 
				
			||||||
| [Jumpy](https://github.com/DavidLGoldberg/jumpy)                      |                             [⬇](https://atom.io/packages/jumpy)                             |                                [Atom](https://atom.io/)                                | :heavy_check_mark:  |                 [CoffeeScript](http://coffeescript.org/)                 |
 | 
					| [Jumpy](https://github.com/DavidLGoldberg/jumpy)                      |                             [⬇](https://atom.io/packages/jumpy)                             |                                [Atom](https://atom.io/)                                | :heavy_check_mark:  |                 [CoffeeScript](http://coffeescript.org/)                 |
 | 
				
			||||||
@@ -170,8 +206,8 @@ The following individuals have significantly improved AceJump through their cont
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
* [John Lindquist](https://github.com/johnlindquist) for creating AceJump and supporting it for many years.
 | 
					* [John Lindquist](https://github.com/johnlindquist) for creating AceJump and supporting it for many years.
 | 
				
			||||||
* [Breandan Considine](https://github.com/breandan) for maintaining the project and adding some new features.
 | 
					* [Breandan Considine](https://github.com/breandan) for maintaining the project and adding some new features.
 | 
				
			||||||
 | 
					* [chylex](https://github.com/chylex) for numerous [performance optimizations](https://github.com/acejump/AceJump/pulls?q=is%3Apr+author%3Achylex), [bug fixes](https://github.com/acejump/AceJump/issues/348#issuecomment-739454920) and [refactoring](https://github.com/acejump/AceJump/pull/353).
 | 
				
			||||||
* [Alex Plate](https://github.com/AlexPl292) for submitting [several PRs](https://github.com/acejump/AceJump/pulls?q=is%3Apr+author%3AAlexPl292).
 | 
					* [Alex Plate](https://github.com/AlexPl292) for submitting [several PRs](https://github.com/acejump/AceJump/pulls?q=is%3Apr+author%3AAlexPl292).
 | 
				
			||||||
* [Daniel Chýlek](https://github.com/chylex) for several [performance optimizations](https://github.com/acejump/AceJump/pulls?q=is%3Apr+author%3Achylex).
 | 
					 | 
				
			||||||
* [Sven Speckmaier](https://github.com/svensp) for [improving](https://github.com/acejump/AceJump/pull/214) search latency.
 | 
					* [Sven Speckmaier](https://github.com/svensp) for [improving](https://github.com/acejump/AceJump/pull/214) search latency.
 | 
				
			||||||
* [Stefan Monnier](https://www.iro.umontreal.ca/~monnier/) for algorithmic advice and maintaining Emacs for several years.
 | 
					* [Stefan Monnier](https://www.iro.umontreal.ca/~monnier/) for algorithmic advice and maintaining Emacs for several years.
 | 
				
			||||||
* [Fool's Mate](https://www.fools-mate.de/) for the [icon](https://github.com/acejump/AceJump/issues/313) and graphic design.
 | 
					* [Fool's Mate](https://www.fools-mate.de/) for the [icon](https://github.com/acejump/AceJump/issues/313) and graphic design.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,13 @@
 | 
				
			|||||||
import org.jetbrains.changelog.closure
 | 
					import org.jetbrains.changelog.*
 | 
				
			||||||
import org.jetbrains.intellij.tasks.PatchPluginXmlTask
 | 
					import org.jetbrains.intellij.tasks.*
 | 
				
			||||||
import org.jetbrains.intellij.tasks.PublishTask
 | 
					 | 
				
			||||||
import org.jetbrains.intellij.tasks.RunIdeTask
 | 
					 | 
				
			||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
 | 
					import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
plugins {
 | 
					plugins {
 | 
				
			||||||
  idea apply true
 | 
					  idea apply true
 | 
				
			||||||
  kotlin("jvm") version "1.3.72"
 | 
					  kotlin("jvm") version "1.6.0-RC2"
 | 
				
			||||||
  id("org.jetbrains.intellij") version "0.7.2"
 | 
					  id("org.jetbrains.intellij") version "1.2.1"
 | 
				
			||||||
  id("org.jetbrains.changelog") version "1.1.2"
 | 
					  id("org.jetbrains.changelog") version "1.3.1"
 | 
				
			||||||
  id("com.github.ben-manes.versions") version "0.38.0"
 | 
					  id("com.github.ben-manes.versions") version "0.39.0"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tasks {
 | 
					tasks {
 | 
				
			||||||
@@ -27,40 +25,49 @@ tasks {
 | 
				
			|||||||
    findProperty("luginDev")?.let { args = listOf(projectDir.absolutePath) }
 | 
					    findProperty("luginDev")?.let { args = listOf(projectDir.absolutePath) }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  withType<PublishTask> {
 | 
					  publishPlugin {
 | 
				
			||||||
    val intellijPublishToken: String? by project
 | 
					    val intellijPublishToken: String? by project
 | 
				
			||||||
    token(intellijPublishToken)
 | 
					    token.set(intellijPublishToken)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  withType<PatchPluginXmlTask> {
 | 
					  patchPluginXml {
 | 
				
			||||||
    sinceBuild("201.6668.0")
 | 
					    sinceBuild.set("203.7717.56")
 | 
				
			||||||
    changeNotes({ changelog.getLatest().toHTML() })
 | 
					    changeNotes.set(provider {
 | 
				
			||||||
 | 
					      changelog.getAll().values.take(2).last().toHTML()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  runPluginVerifier {
 | 
				
			||||||
 | 
					    ideVersions.set(listOf("2021.2.1"))
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
changelog {
 | 
					changelog {
 | 
				
			||||||
  path = "${project.projectDir}/CHANGES.md"
 | 
					  version.set("3.8.5")
 | 
				
			||||||
  header = closure { "${project.version}" }
 | 
					  path.set("${project.projectDir}/CHANGES.md")
 | 
				
			||||||
}
 | 
					  header.set(provider { "[${project.version}] - ${date()}" })
 | 
				
			||||||
 | 
					  itemPrefix.set("-")
 | 
				
			||||||
dependencies {
 | 
					  unreleasedTerm.set("Unreleased")
 | 
				
			||||||
  // gradle-intellij-plugin doesn't attach sources properly for Kotlin :(
 | 
					 | 
				
			||||||
  compileOnly(kotlin("stdlib-jdk8"))
 | 
					 | 
				
			||||||
  // https://github.com/promeG/TinyPinyin
 | 
					 | 
				
			||||||
  implementation("com.github.promeg:tinypinyin:2.0.3")
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
repositories {
 | 
					repositories {
 | 
				
			||||||
  mavenCentral()
 | 
					  mavenCentral()
 | 
				
			||||||
  jcenter()
 | 
					  maven("https://jitpack.io")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dependencies {
 | 
				
			||||||
 | 
					  // gradle-intellij-plugin doesn't attach sources properly for Kotlin :(
 | 
				
			||||||
 | 
					  implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
 | 
				
			||||||
 | 
					  compileOnly(kotlin("stdlib-jdk8"))
 | 
				
			||||||
 | 
					  implementation("com.anyascii:anyascii:0.3.0")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
intellij {
 | 
					intellij {
 | 
				
			||||||
  version = "2020.2"
 | 
					  version.set("2021.2.1")
 | 
				
			||||||
  pluginName = "AceJump"
 | 
					  pluginName.set("AceJump")
 | 
				
			||||||
  updateSinceUntilBuild = false
 | 
					  updateSinceUntilBuild.set(false)
 | 
				
			||||||
  setPlugins("java")
 | 
					  plugins.set(listOf("java"))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
group = "org.acejump"
 | 
					group = "org.acejump"
 | 
				
			||||||
version = "3.7"
 | 
					version = "3.8.5"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							@@ -1,5 +1,5 @@
 | 
				
			|||||||
distributionBase=GRADLE_USER_HOME
 | 
					distributionBase=GRADLE_USER_HOME
 | 
				
			||||||
distributionPath=wrapper/dists
 | 
					distributionPath=wrapper/dists
 | 
				
			||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
 | 
					distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
 | 
				
			||||||
zipStoreBase=GRADLE_USER_HOME
 | 
					zipStoreBase=GRADLE_USER_HOME
 | 
				
			||||||
zipStorePath=wrapper/dists
 | 
					zipStorePath=wrapper/dists
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,34 +1,64 @@
 | 
				
			|||||||
package org.acejump
 | 
					package org.acejump
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.anyascii.AnyAscii
 | 
				
			||||||
 | 
					import com.intellij.diff.util.DiffUtil.getLineCount
 | 
				
			||||||
 | 
					import com.intellij.openapi.editor.*
 | 
				
			||||||
 | 
					import it.unimi.dsi.fastutil.ints.IntArrayList
 | 
				
			||||||
 | 
					import org.acejump.config.AceConfig
 | 
				
			||||||
 | 
					import kotlin.math.*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This annotation is a marker which means that the annotated function is
 | 
				
			||||||
 | 
					 *   used in external plugins.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Retention(AnnotationRetention.SOURCE)
 | 
				
			||||||
annotation class ExternalUsage
 | 
					annotation class ExternalUsage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Returns an immutable version of the currently edited document.
 | 
					 * Returns an immutable version of the currently edited document.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
val Editor.immutableText
 | 
					val Editor.immutableText get() = EditorsCache.getText(this)
 | 
				
			||||||
  get() = this.document.immutableCharSequence
 | 
					
 | 
				
			||||||
 | 
					object EditorsCache {
 | 
				
			||||||
 | 
					  private var stale = true
 | 
				
			||||||
 | 
					  fun invalidate() {
 | 
				
			||||||
 | 
					    stale = true
 | 
				
			||||||
 | 
					    editorTexts.clear()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private val editorTexts = mutableMapOf<Editor, CharSequence>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun getText(editor: Editor) =
 | 
				
			||||||
 | 
					    if (stale || editor !in editorTexts)
 | 
				
			||||||
 | 
					      editor.document.immutableCharSequence
 | 
				
			||||||
 | 
					        .let { if (AceConfig.mapToASCII) it.mapToASCII() else it }
 | 
				
			||||||
 | 
					        .also { editorTexts[editor] = it; stale = false }
 | 
				
			||||||
 | 
					    else editorTexts[editor]!!
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun CharSequence.mapToASCII() =
 | 
				
			||||||
 | 
					  map { AnyAscii.transliterate("$it").first() }.joinToString("")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Returns true if [this] contains [otherText] at the specified offset.
 | 
					 * Returns true if [this] contains [otherText] at the specified offset.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
fun CharSequence.matchesAt(selfOffset: Int, otherText: String, ignoreCase: Boolean): Boolean {
 | 
					fun CharSequence.matchesAt(selfOffset: Int, otherText: String, ignoreCase: Boolean) =
 | 
				
			||||||
  return this.regionMatches(selfOffset, otherText, 0, otherText.length, ignoreCase)
 | 
					  regionMatches(selfOffset, otherText, 0, otherText.length, ignoreCase)
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Calculates the length of a common prefix in [this] starting at index [selfOffset], and [otherText] starting at index 0.
 | 
					 * Calculates the length of a common prefix in [this] starting
 | 
				
			||||||
 | 
					 * at index [selfOffset], and [otherText] starting at index 0.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
fun CharSequence.countMatchingCharacters(selfOffset: Int, otherText: String): Int {
 | 
					fun CharSequence.countMatchingCharacters(selfOffset: Int, otherText: String): Int {
 | 
				
			||||||
  var i = 0
 | 
					  var i = 0
 | 
				
			||||||
  var o = selfOffset + i
 | 
					  var o = selfOffset + i
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  while (i < otherText.length && o < this.length && otherText[i].equals(this[o], ignoreCase = true)) {
 | 
					  while (i < otherText.length && o < this.length && otherText[i].equals(this[o], ignoreCase = true)) {
 | 
				
			||||||
    i++
 | 
					    i++
 | 
				
			||||||
    o++
 | 
					    o++
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  return i
 | 
					  return i
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -41,42 +71,185 @@ val Char.isWordPart
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Finds index of the first character in a word.
 | 
					 * Finds index of the first character in a word.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
inline fun CharSequence.wordStart(pos: Int, isPartOfWord: (Char) -> Boolean = Char::isWordPart): Int {
 | 
					inline fun CharSequence.wordStart(
 | 
				
			||||||
 | 
					  pos: Int, isPartOfWord: (Char) -> Boolean = Char::isWordPart
 | 
				
			||||||
 | 
					): Int {
 | 
				
			||||||
  var start = pos
 | 
					  var start = pos
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  while (start > 0 && isPartOfWord(this[start - 1])) {
 | 
					  while (start > 0 && isPartOfWord(this[start - 1])) --start
 | 
				
			||||||
    --start
 | 
					
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  return start
 | 
					  return start
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Finds index of the last character in a word.
 | 
					 * Finds index of the last character in a word.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
inline fun CharSequence.wordEnd(pos: Int, isPartOfWord: (Char) -> Boolean = Char::isWordPart): Int {
 | 
					inline fun CharSequence.wordEnd(
 | 
				
			||||||
 | 
					  pos: Int, isPartOfWord: (Char) -> Boolean = Char::isWordPart
 | 
				
			||||||
 | 
					): Int {
 | 
				
			||||||
  var end = pos
 | 
					  var end = pos
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  while (end < length - 1 && isPartOfWord(this[end + 1])) {
 | 
					  while (end < length - 1 && isPartOfWord(this[end + 1])) ++end
 | 
				
			||||||
    ++end
 | 
					
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  return end
 | 
					  return end
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Finds index of the first word character following a sequence of non-word characters following the end of a word.
 | 
					 * Finds index of the first word character following a sequence of non-word
 | 
				
			||||||
 | 
					 * characters following the end of a word.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
inline fun CharSequence.wordEndPlus(pos: Int, isPartOfWord: (Char) -> Boolean = Char::isWordPart): Int {
 | 
					inline fun CharSequence.wordEndPlus(
 | 
				
			||||||
 | 
					  pos: Int, isPartOfWord: (Char) -> Boolean = Char::isWordPart
 | 
				
			||||||
 | 
					): Int {
 | 
				
			||||||
  var end = this.wordEnd(pos, isPartOfWord)
 | 
					  var end = this.wordEnd(pos, isPartOfWord)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  while (end < length - 1 && !isPartOfWord(this[end + 1])) {
 | 
					  while (end < length - 1 && !isPartOfWord(this[end + 1])) ++end
 | 
				
			||||||
    ++end
 | 
					
 | 
				
			||||||
  }
 | 
					  if (end < length - 1 && isPartOfWord(this[end + 1])) ++end
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  if (end < length - 1 && isPartOfWord(this[end + 1])) {
 | 
					 | 
				
			||||||
    ++end
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  return end
 | 
					  return end
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun MutableMap<Editor, IntArrayList>.clone(): MutableMap<Editor, IntArrayList> {
 | 
				
			||||||
 | 
					  val clone = HashMap<Editor, IntArrayList>(size)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for ((editor, offsets) in this) {
 | 
				
			||||||
 | 
					    clone[editor] = offsets.clone()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return clone
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun Editor.offsetCenter(first: Int, second: Int): LogicalPosition {
 | 
				
			||||||
 | 
					  val firstIndexLine = offsetToLogicalPosition(first).line
 | 
				
			||||||
 | 
					  val lastIndexLine = offsetToLogicalPosition(second).line
 | 
				
			||||||
 | 
					  val center = (firstIndexLine + lastIndexLine) / 2
 | 
				
			||||||
 | 
					  return offsetToLogicalPosition(getLineStartOffset(center))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun Editor.getView(): IntRange {
 | 
				
			||||||
 | 
					  val firstVisibleLine = max(0, getVisualLineAtTopOfScreen() - 1)
 | 
				
			||||||
 | 
					  val firstLine = visualLineToLogicalLine(firstVisibleLine)
 | 
				
			||||||
 | 
					  val startOffset = getLineStartOffset(firstLine)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  val height = getScreenHeight() + 2
 | 
				
			||||||
 | 
					  val lastLine = visualLineToLogicalLine(firstVisibleLine + height)
 | 
				
			||||||
 | 
					  var endOffset = getLineEndOffset(lastLine, true)
 | 
				
			||||||
 | 
					  endOffset = normalizeOffset(lastLine, endOffset)
 | 
				
			||||||
 | 
					  endOffset = min(max(0, document.textLength - 1), endOffset + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return startOffset..endOffset
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Returns the offset of the start of the requested line.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param line   The logical line to get the start offset for.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return 0 if line is < 0, file size of line is bigger than file, else the
 | 
				
			||||||
 | 
					 *         start offset for the line
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun Editor.getLineStartOffset(line: Int) =
 | 
				
			||||||
 | 
					  when {
 | 
				
			||||||
 | 
					    line < 0 -> 0
 | 
				
			||||||
 | 
					    line >= getLineCount(document) -> getFileSize()
 | 
				
			||||||
 | 
					    else -> document.getLineStartOffset(line)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Returns the offset of the end of the requested line.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param line     The logical line to get the end offset for
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param allowEnd True include newline
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return 0 if line is < 0, file size of line is bigger than file, else the
 | 
				
			||||||
 | 
					 * end offset for the line
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun Editor.getLineEndOffset(line: Int, allowEnd: Boolean = true) =
 | 
				
			||||||
 | 
					  when {
 | 
				
			||||||
 | 
					    line < 0 -> 0
 | 
				
			||||||
 | 
					    line >= getLineCount(document) -> getFileSize(allowEnd)
 | 
				
			||||||
 | 
					    else -> document.getLineEndOffset(line) - if (allowEnd) 0 else 1
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Gets the number of lines than can be displayed on the screen at one time.
 | 
				
			||||||
 | 
					 * This is rounded down to the nearest whole line if there is a partial line
 | 
				
			||||||
 | 
					 * visible at the bottom of the screen.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return The number of screen lines
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun Editor.getScreenHeight() =
 | 
				
			||||||
 | 
					  (scrollingModel.visibleArea.y + scrollingModel.visibleArea.height -
 | 
				
			||||||
 | 
					    getVisualLineAtTopOfScreen() * lineHeight) / lineHeight
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This is a set of helper methods for working with editors.
 | 
				
			||||||
 | 
					 * All line and column values are zero based.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun Editor.getVisualLineAtTopOfScreen() =
 | 
				
			||||||
 | 
					  (scrollingModel.verticalScrollOffset + lineHeight - 1) / lineHeight
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Gets the actual number of characters in the file
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param countNewLines True include newline
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return The file's character count
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun Editor.getFileSize(countNewLines: Boolean = false): Int {
 | 
				
			||||||
 | 
					  val len = document.textLength
 | 
				
			||||||
 | 
					  val doc = document.charsSequence
 | 
				
			||||||
 | 
					  return if (countNewLines || len == 0 || doc[len - 1] != '\n') len else len - 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Ensures that the supplied logical line is within the range 0 (incl) and the
 | 
				
			||||||
 | 
					 * number of logical lines in the file (excl).
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param line   The logical line number to normalize
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return The normalized logical line number
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun Editor.normalizeLine(line: Int) = max(0, min(line, getLineCount(document) - 1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Converts a visual line number to a logical line number.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param line   The visual line number to convert
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return The logical line number
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun Editor.visualLineToLogicalLine(line: Int) =
 | 
				
			||||||
 | 
					  normalizeLine(visualToLogicalPosition(
 | 
				
			||||||
 | 
					    VisualPosition(line.coerceAtLeast(0), 0)).line)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Ensures that the supplied offset for the given logical line is within the
 | 
				
			||||||
 | 
					 * range for the line. If allowEnd is true, the range will allow for the offset
 | 
				
			||||||
 | 
					 * to be one past the last character on the line.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param line     The logical line number
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param offset   The offset to normalize
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param allowEnd true if the offset can be one past the last character on the
 | 
				
			||||||
 | 
					 *                 line, false if not
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return The normalized column number
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun Editor.normalizeOffset(line: Int, offset: Int, allowEnd: Boolean = true) =
 | 
				
			||||||
 | 
					  if (getFileSize(allowEnd) == 0) 0 else
 | 
				
			||||||
 | 
					    max(min(offset, getLineEndOffset(line, allowEnd)), getLineStartOffset(line))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,70 +2,91 @@ package org.acejump.action
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.intellij.openapi.actionSystem.AnActionEvent
 | 
					import com.intellij.openapi.actionSystem.AnActionEvent
 | 
				
			||||||
import com.intellij.openapi.actionSystem.CommonDataKeys.EDITOR
 | 
					import com.intellij.openapi.actionSystem.CommonDataKeys.EDITOR
 | 
				
			||||||
 | 
					import com.intellij.openapi.fileEditor.TextEditor
 | 
				
			||||||
 | 
					import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
 | 
				
			||||||
import com.intellij.openapi.project.DumbAwareAction
 | 
					import com.intellij.openapi.project.DumbAwareAction
 | 
				
			||||||
 | 
					import com.intellij.util.IncorrectOperationException
 | 
				
			||||||
import org.acejump.boundaries.Boundaries
 | 
					import org.acejump.boundaries.Boundaries
 | 
				
			||||||
import org.acejump.boundaries.StandardBoundaries
 | 
					import org.acejump.boundaries.StandardBoundaries.*
 | 
				
			||||||
import org.acejump.input.JumpMode
 | 
					import org.acejump.input.JumpMode
 | 
				
			||||||
 | 
					import org.acejump.input.JumpMode.*
 | 
				
			||||||
import org.acejump.search.Pattern
 | 
					import org.acejump.search.Pattern
 | 
				
			||||||
 | 
					import org.acejump.search.Pattern.*
 | 
				
			||||||
import org.acejump.session.Session
 | 
					import org.acejump.session.Session
 | 
				
			||||||
import org.acejump.session.SessionManager
 | 
					import org.acejump.session.SessionManager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Base class for keyboard-activated actions that create or update an AceJump [Session].
 | 
					 * Base class for keyboard-activated actions that create or update an AceJump [Session].
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
sealed class AceAction : DumbAwareAction() {
 | 
					sealed class AceAction: DumbAwareAction() {
 | 
				
			||||||
  final override fun update(action: AnActionEvent) {
 | 
					  final override fun update(action: AnActionEvent) {
 | 
				
			||||||
    action.presentation.isEnabled = action.getData(EDITOR) != null
 | 
					    action.presentation.isEnabled = action.getData(EDITOR) != null
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  final override fun actionPerformed(e: AnActionEvent) {
 | 
					  final override fun actionPerformed(e: AnActionEvent) {
 | 
				
			||||||
    invoke(SessionManager.start(e.getData(EDITOR) ?: return))
 | 
					    val editor = e.getData(EDITOR) ?: return
 | 
				
			||||||
 | 
					    val project = e.project
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					    if (project != null) {
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
 | 
					        val openEditors = FileEditorManagerEx.getInstanceEx(project).splitters.selectedEditors
 | 
				
			||||||
 | 
					          .mapNotNull { (it as? TextEditor)?.editor }
 | 
				
			||||||
 | 
					          .sortedBy { if (it === editor) 0 else 1 }
 | 
				
			||||||
 | 
					        invoke(SessionManager.start(editor, openEditors))
 | 
				
			||||||
 | 
					      } catch (e: IncorrectOperationException) {
 | 
				
			||||||
 | 
					        invoke(SessionManager.start(editor))
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					      invoke(SessionManager.start(editor))
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  abstract operator fun invoke(session: Session)
 | 
					  abstract operator fun invoke(session: Session)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Generic action type that toggles a specific [JumpMode].
 | 
					   * Generic action type that toggles a specific [JumpMode].
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  abstract class BaseToggleJumpModeAction(private val mode: JumpMode) : AceAction() {
 | 
					  abstract class BaseToggleJumpModeAction(private val mode: JumpMode): AceAction() {
 | 
				
			||||||
    final override fun invoke(session: Session) = session.toggleJumpMode(mode)
 | 
					    final override fun invoke(session: Session) = session.toggleJumpMode(mode)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Generic action type that starts a regex search.
 | 
					   * Generic action type that starts a regex search.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  abstract class BaseRegexSearchAction(private val pattern: Pattern, private val boundaries: Boundaries) : AceAction() {
 | 
					  abstract class BaseRegexSearchAction(private val pattern: Pattern, private val boundaries: Boundaries): AceAction() {
 | 
				
			||||||
    override fun invoke(session: Session) = session.startRegexSearch(pattern, boundaries)
 | 
					    override fun invoke(session: Session) = session.startRegexSearch(pattern, boundaries)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Initiates an AceJump session in the first [JumpMode], or cycles to the next [JumpMode] as defined in configuration.
 | 
					   * Initiates an AceJump session in the first [JumpMode], or cycles to the next [JumpMode] as defined in configuration.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  object ActivateOrCycleMode : AceAction() {
 | 
					  class ActivateOrCycleMode: AceAction() {
 | 
				
			||||||
    override fun invoke(session: Session) = session.cycleNextJumpMode()
 | 
					    override fun invoke(session: Session) = session.cycleNextJumpMode()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Initiates an AceJump session in the last [JumpMode], or cycles to the previous [JumpMode] as defined in configuration.
 | 
					   * Initiates an AceJump session in the last [JumpMode], or cycles to the previous [JumpMode] as defined in configuration.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  object ActivateOrReverseCycleMode : AceAction() {
 | 
					  class ActivateOrReverseCycleMode: AceAction() {
 | 
				
			||||||
    override fun invoke(session: Session) = session.cyclePreviousJumpMode()
 | 
					    override fun invoke(session: Session) = session.cyclePreviousJumpMode()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  // @formatter:off
 | 
					  // @formatter:off
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  object ToggleJumpMode        : BaseToggleJumpModeAction(JumpMode.JUMP)
 | 
					  class ToggleJumpMode        : BaseToggleJumpModeAction(JUMP)
 | 
				
			||||||
  object ToggleJumpEndMode     : BaseToggleJumpModeAction(JumpMode.JUMP_END)
 | 
					  class ToggleJumpEndMode     : BaseToggleJumpModeAction(JUMP_END)
 | 
				
			||||||
  object ToggleTargetMode      : BaseToggleJumpModeAction(JumpMode.TARGET)
 | 
					  class ToggleTargetMode      : BaseToggleJumpModeAction(TARGET)
 | 
				
			||||||
  object ToggleDeclarationMode : BaseToggleJumpModeAction(JumpMode.DEFINE)
 | 
					  class ToggleDeclarationMode : BaseToggleJumpModeAction(DECLARATION)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  object StartAllWordsMode          : BaseRegexSearchAction(Pattern.ALL_WORDS, StandardBoundaries.WHOLE_FILE)
 | 
					
 | 
				
			||||||
  object StartAllWordsBackwardsMode : BaseRegexSearchAction(Pattern.ALL_WORDS, StandardBoundaries.BEFORE_CARET)
 | 
					  class StartAllWordsMode          : BaseRegexSearchAction(ALL_WORDS, WHOLE_FILE)
 | 
				
			||||||
  object StartAllWordsForwardMode   : BaseRegexSearchAction(Pattern.ALL_WORDS, StandardBoundaries.AFTER_CARET)
 | 
					  class StartAllWordsBackwardsMode : BaseRegexSearchAction(ALL_WORDS, BEFORE_CARET)
 | 
				
			||||||
  object StartAllLineStartsMode     : BaseRegexSearchAction(Pattern.LINE_STARTS, StandardBoundaries.WHOLE_FILE)
 | 
					  class StartAllWordsForwardMode   : BaseRegexSearchAction(ALL_WORDS, AFTER_CARET)
 | 
				
			||||||
  object StartAllLineEndsMode       : BaseRegexSearchAction(Pattern.LINE_ENDS, StandardBoundaries.WHOLE_FILE)
 | 
					  class StartAllLineStartsMode     : BaseRegexSearchAction(LINE_STARTS, WHOLE_FILE)
 | 
				
			||||||
  object StartAllLineIndentsMode    : BaseRegexSearchAction(Pattern.LINE_INDENTS, StandardBoundaries.WHOLE_FILE)
 | 
					  class StartAllLineEndsMode       : BaseRegexSearchAction(LINE_ENDS, WHOLE_FILE)
 | 
				
			||||||
  object StartAllLineMarksMode      : BaseRegexSearchAction(Pattern.LINE_ALL_MARKS, StandardBoundaries.WHOLE_FILE)
 | 
					  class StartAllLineIndentsMode    : BaseRegexSearchAction(LINE_INDENTS, WHOLE_FILE)
 | 
				
			||||||
  
 | 
					  class StartAllLineMarksMode      : BaseRegexSearchAction(LINE_ALL_MARKS, WHOLE_FILE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // @formatter:on
 | 
					  // @formatter:on
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,59 +4,63 @@ import com.intellij.openapi.actionSystem.DataContext
 | 
				
			|||||||
import com.intellij.openapi.editor.Caret
 | 
					import com.intellij.openapi.editor.Caret
 | 
				
			||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
 | 
					import com.intellij.openapi.editor.actionSystem.EditorActionHandler
 | 
				
			||||||
import org.acejump.boundaries.StandardBoundaries
 | 
					import org.acejump.boundaries.StandardBoundaries.*
 | 
				
			||||||
import org.acejump.search.Pattern
 | 
					import org.acejump.search.Pattern.*
 | 
				
			||||||
import org.acejump.session.Session
 | 
					import org.acejump.session.Session
 | 
				
			||||||
import org.acejump.session.SessionManager
 | 
					import org.acejump.session.SessionManager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Base class for keyboard-activated overrides of existing editor actions, that have a different meaning during an AceJump [Session].
 | 
					 * Base class for keyboard-activated overrides of existing editor actions, that have a different meaning during an AceJump [Session].
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
sealed class AceEditorAction(private val originalHandler: EditorActionHandler) : EditorActionHandler() {
 | 
					sealed class AceEditorAction(private val originalHandler: EditorActionHandler): EditorActionHandler() {
 | 
				
			||||||
  final override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?): Boolean {
 | 
					  final override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?): Boolean =
 | 
				
			||||||
    return SessionManager[editor] != null || originalHandler.isEnabled(editor, caret, dataContext)
 | 
					    SessionManager[editor] != null || originalHandler.isEnabled(editor, caret, dataContext)
 | 
				
			||||||
  }
 | 
					
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  final override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
 | 
					  final override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
 | 
				
			||||||
    val session = SessionManager[editor]
 | 
					    val session = SessionManager[editor]
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (session != null) {
 | 
					    if (session != null) run(session)
 | 
				
			||||||
      run(session)
 | 
					    else if (originalHandler.isEnabled(editor, caret, dataContext))
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else if (originalHandler.isEnabled(editor, caret, dataContext)) {
 | 
					 | 
				
			||||||
      originalHandler.execute(editor, caret, dataContext)
 | 
					      originalHandler.execute(editor, caret, dataContext)
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  protected abstract fun run(session: Session)
 | 
					  protected abstract fun run(session: Session)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  // Actions
 | 
					  // Actions
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  class Reset(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
 | 
					  class Reset(originalHandler: EditorActionHandler): AceEditorAction(originalHandler) {
 | 
				
			||||||
    override fun run(session: Session) = session.end()
 | 
					    override fun run(session: Session) = session.end()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  class ClearSearch(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
 | 
					  class ClearSearch(originalHandler: EditorActionHandler): AceEditorAction(originalHandler) {
 | 
				
			||||||
    override fun run(session: Session) = session.restart()
 | 
					    override fun run(session: Session) = session.restart()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  class SelectBackward(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
 | 
					  class SelectBackward(originalHandler: EditorActionHandler): AceEditorAction(originalHandler) {
 | 
				
			||||||
    override fun run(session: Session) = session.visitPreviousTag()
 | 
					    override fun run(session: Session) = session.visitPreviousTag()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  class SelectForward(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
 | 
					  class SelectForward(originalHandler: EditorActionHandler): AceEditorAction(originalHandler) {
 | 
				
			||||||
    override fun run(session: Session) = session.visitNextTag()
 | 
					    override fun run(session: Session) = session.visitNextTag()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  class SearchLineStarts(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
 | 
					  class ScrollToNextScreenful(originalHandler: EditorActionHandler): AceEditorAction(originalHandler) {
 | 
				
			||||||
    override fun run(session: Session) = session.startRegexSearch(Pattern.LINE_STARTS, StandardBoundaries.WHOLE_FILE)
 | 
					    override fun run(session: Session) { session.scrollToNextScreenful() }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  class SearchLineEnds(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
 | 
					  class ScrollToPreviousScreenful(originalHandler: EditorActionHandler): AceEditorAction(originalHandler) {
 | 
				
			||||||
    override fun run(session: Session) = session.startRegexSearch(Pattern.LINE_ENDS, StandardBoundaries.WHOLE_FILE)
 | 
					    override fun run(session: Session) { session.scrollToPreviousScreenful() }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  class SearchLineIndents(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
 | 
					  class SearchLineStarts(originalHandler: EditorActionHandler): AceEditorAction(originalHandler) {
 | 
				
			||||||
    override fun run(session: Session) = session.startRegexSearch(Pattern.LINE_INDENTS, StandardBoundaries.WHOLE_FILE)
 | 
					    override fun run(session: Session) = session.startRegexSearch(LINE_STARTS, WHOLE_FILE)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  class SearchLineEnds(originalHandler: EditorActionHandler): AceEditorAction(originalHandler) {
 | 
				
			||||||
 | 
					    override fun run(session: Session) = session.startRegexSearch(LINE_ENDS, WHOLE_FILE)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  class SearchLineIndents(originalHandler: EditorActionHandler): AceEditorAction(originalHandler) {
 | 
				
			||||||
 | 
					    override fun run(session: Session) = session.startRegexSearch(LINE_INDENTS, WHOLE_FILE)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,14 +1,14 @@
 | 
				
			|||||||
package org.acejump.action
 | 
					package org.acejump.action
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction
 | 
					import com.intellij.openapi.actionSystem.*
 | 
				
			||||||
import com.intellij.codeInsight.navigation.actions.GotoTypeDeclarationAction
 | 
					import com.intellij.openapi.actionSystem.IdeActions.*
 | 
				
			||||||
import com.intellij.openapi.actionSystem.ActionManager
 | 
					 | 
				
			||||||
import com.intellij.openapi.actionSystem.AnAction
 | 
					 | 
				
			||||||
import com.intellij.openapi.command.CommandProcessor
 | 
					import com.intellij.openapi.command.CommandProcessor
 | 
				
			||||||
import com.intellij.openapi.command.UndoConfirmationPolicy
 | 
					import com.intellij.openapi.command.UndoConfirmationPolicy
 | 
				
			||||||
import com.intellij.openapi.editor.Document
 | 
					import com.intellij.openapi.editor.Document
 | 
				
			||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
import com.intellij.openapi.editor.actionSystem.DocCommandGroupId
 | 
					import com.intellij.openapi.editor.actionSystem.DocCommandGroupId
 | 
				
			||||||
 | 
					import com.intellij.openapi.fileEditor.TextEditor
 | 
				
			||||||
 | 
					import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
 | 
				
			||||||
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory
 | 
					import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory
 | 
				
			||||||
import com.intellij.openapi.project.Project
 | 
					import com.intellij.openapi.project.Project
 | 
				
			||||||
import com.intellij.openapi.ui.playback.commands.ActionCommand
 | 
					import com.intellij.openapi.ui.playback.commands.ActionCommand
 | 
				
			||||||
@@ -16,93 +16,110 @@ import org.acejump.*
 | 
				
			|||||||
import org.acejump.input.JumpMode
 | 
					import org.acejump.input.JumpMode
 | 
				
			||||||
import org.acejump.input.JumpMode.*
 | 
					import org.acejump.input.JumpMode.*
 | 
				
			||||||
import org.acejump.search.SearchProcessor
 | 
					import org.acejump.search.SearchProcessor
 | 
				
			||||||
 | 
					import org.acejump.search.Tag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Performs [JumpMode] navigation and actions.
 | 
					 * Performs [JumpMode] navigation and actions.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal class TagJumper(private val editor: Editor, private val mode: JumpMode, private val searchProcessor: SearchProcessor?) {
 | 
					internal class TagJumper(private val mode: JumpMode, private val searchProcessor: SearchProcessor?) {
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Moves caret to a specific offset in the editor according to the positioning and selection rules of the current [JumpMode].
 | 
					   * Moves caret to a specific offset in the editor according to the positioning and selection rules of the current [JumpMode].
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun visit(offset: Int) {
 | 
					  fun visit(tag: Tag) {
 | 
				
			||||||
 | 
					    val editor = tag.editor
 | 
				
			||||||
 | 
					    val offset = tag.offset
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    if (mode === JUMP_END || mode === TARGET) {
 | 
					    if (mode === JUMP_END || mode === TARGET) {
 | 
				
			||||||
      val chars = editor.immutableText
 | 
					      val chars = editor.immutableText
 | 
				
			||||||
      val matchingChars = searchProcessor?.let { chars.countMatchingCharacters(offset, it.query.rawText) } ?: 0
 | 
					      val matchingChars = searchProcessor?.let { chars.countMatchingCharacters(offset, it.query.rawText) } ?: 0
 | 
				
			||||||
      val targetOffset = offset + matchingChars
 | 
					      val targetOffset = offset + matchingChars
 | 
				
			||||||
      val isInsideWord = matchingChars > 0 && chars[targetOffset - 1].isWordPart && chars[targetOffset].isWordPart
 | 
					      val isInsideWord = matchingChars > 0 && chars[targetOffset - 1].isWordPart && chars[targetOffset].isWordPart
 | 
				
			||||||
      val finalTargetOffset = if (isInsideWord) chars.wordEnd(targetOffset) + 1 else targetOffset
 | 
					      val finalTargetOffset = if (isInsideWord) chars.wordEnd(targetOffset) + 1 else targetOffset
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      if (mode === JUMP_END) {
 | 
					      if (mode === JUMP_END) {
 | 
				
			||||||
        moveCaretTo(editor, finalTargetOffset)
 | 
					        moveCaretTo(editor, finalTargetOffset)
 | 
				
			||||||
      }
 | 
					      } else if (mode === TARGET) {
 | 
				
			||||||
      else if (mode === TARGET) {
 | 
					 | 
				
			||||||
        if (isInsideWord) {
 | 
					        if (isInsideWord) {
 | 
				
			||||||
          selectRange(editor, chars.wordStart(targetOffset), finalTargetOffset)
 | 
					          selectRange(editor, chars.wordStart(targetOffset), finalTargetOffset)
 | 
				
			||||||
        }
 | 
					        } else {
 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
          selectRange(editor, offset, finalTargetOffset)
 | 
					          selectRange(editor, offset, finalTargetOffset)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    } else {
 | 
				
			||||||
    else {
 | 
					 | 
				
			||||||
      moveCaretTo(editor, offset)
 | 
					      moveCaretTo(editor, offset)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Updates caret and selection by [visit]ing a specific offset in the editor, and applying session-finalizing [JumpMode] actions such as
 | 
					   * Updates caret and selection by [visit]ing a specific offset in the editor, and applying session-finalizing [JumpMode] actions such as
 | 
				
			||||||
   * using the Go To Declaration action, or selecting text between caret and target offset/word if Shift was held during the jump.
 | 
					   * using the Go To Declaration action, or selecting text between caret and target offset/word if Shift was held during the jump.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun jump(offset: Int, shiftMode: Boolean) {
 | 
					  fun jump(tag: Tag, shiftMode: Boolean, isCrossEditor: Boolean) {
 | 
				
			||||||
 | 
					    val editor = tag.editor
 | 
				
			||||||
    val oldOffset = editor.caretModel.offset
 | 
					    val oldOffset = editor.caretModel.offset
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    visit(offset)
 | 
					    visit(tag)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (mode === DEFINE) {
 | 
					    if (mode === DECLARATION) {
 | 
				
			||||||
      performAction(if (shiftMode) GotoTypeDeclarationAction() else GotoDeclarationAction())
 | 
					      performAction(ActionManager.getInstance().getAction(if (shiftMode) ACTION_GOTO_TYPE_DECLARATION else ACTION_GOTO_DECLARATION))
 | 
				
			||||||
      return
 | 
					      return
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (shiftMode) {
 | 
					    if (shiftMode && !isCrossEditor) {
 | 
				
			||||||
      val newOffset = editor.caretModel.offset
 | 
					      val newOffset = editor.caretModel.offset
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      if (mode === TARGET) {
 | 
					      if (mode === TARGET) {
 | 
				
			||||||
        selectRange(editor, oldOffset, when {
 | 
					        selectRange(
 | 
				
			||||||
          newOffset < oldOffset -> editor.selectionModel.selectionStart
 | 
					          editor, oldOffset, when {
 | 
				
			||||||
          else                  -> editor.selectionModel.selectionEnd
 | 
					            newOffset < oldOffset -> editor.selectionModel.selectionStart
 | 
				
			||||||
        })
 | 
					            else -> editor.selectionModel.selectionEnd
 | 
				
			||||||
      }
 | 
					          }
 | 
				
			||||||
      else {
 | 
					        )
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
        selectRange(editor, oldOffset, newOffset)
 | 
					        selectRange(editor, oldOffset, newOffset)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private companion object {
 | 
					  private companion object {
 | 
				
			||||||
    private fun moveCaretTo(editor: Editor, offset: Int) = with(editor) {
 | 
					    private fun moveCaretTo(editor: Editor, offset: Int) = with(editor) {
 | 
				
			||||||
 | 
					      ensureEditorFocused(this)
 | 
				
			||||||
      project?.let { addCurrentPositionToHistory(it, document) }
 | 
					      project?.let { addCurrentPositionToHistory(it, document) }
 | 
				
			||||||
      selectionModel.removeSelection(true)
 | 
					      selectionModel.removeSelection(true)
 | 
				
			||||||
      caretModel.moveToOffset(offset)
 | 
					      caretModel.moveToOffset(offset)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    private fun selectRange(editor: Editor, fromOffset: Int, toOffset: Int) = with(editor) {
 | 
					    private fun selectRange(editor: Editor, fromOffset: Int, toOffset: Int) = with(editor) {
 | 
				
			||||||
 | 
					      ensureEditorFocused(this)
 | 
				
			||||||
      selectionModel.removeSelection(true)
 | 
					      selectionModel.removeSelection(true)
 | 
				
			||||||
      selectionModel.setSelection(fromOffset, toOffset)
 | 
					      selectionModel.setSelection(fromOffset, toOffset)
 | 
				
			||||||
      caretModel.moveToOffset(toOffset)
 | 
					      caretModel.moveToOffset(toOffset)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					    private fun ensureEditorFocused(editor: Editor) {
 | 
				
			||||||
 | 
					      val project = editor.project ?: return
 | 
				
			||||||
 | 
					      val fem = FileEditorManagerEx.getInstanceEx(project)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					      val window = fem.windows.firstOrNull { (it.selectedEditor?.selectedWithProvider?.fileEditor as? TextEditor)?.editor === editor }
 | 
				
			||||||
 | 
					      if (window != null && window !== fem.currentWindow) {
 | 
				
			||||||
 | 
					        fem.currentWindow = window
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private fun addCurrentPositionToHistory(project: Project, document: Document) {
 | 
					    private fun addCurrentPositionToHistory(project: Project, document: Document) {
 | 
				
			||||||
      CommandProcessor.getInstance().executeCommand(project, {
 | 
					      CommandProcessor.getInstance().executeCommand(
 | 
				
			||||||
        with(IdeDocumentHistory.getInstance(project)) {
 | 
					        project, {
 | 
				
			||||||
          setCurrentCommandHasMoves()
 | 
					          with(IdeDocumentHistory.getInstance(project)) {
 | 
				
			||||||
          includeCurrentCommandAsNavigation()
 | 
					            setCurrentCommandHasMoves()
 | 
				
			||||||
          includeCurrentPlaceAsChangePlace()
 | 
					            includeCurrentCommandAsNavigation()
 | 
				
			||||||
        }
 | 
					            includeCurrentPlaceAsChangePlace()
 | 
				
			||||||
      }, "AceJumpHistoryAppender", DocCommandGroupId.noneGroupId(document), UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION, document)
 | 
					          }
 | 
				
			||||||
    }
 | 
					        }, "AceJumpHistoryAppender", DocCommandGroupId.noneGroupId(document),
 | 
				
			||||||
    
 | 
					        UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION, document
 | 
				
			||||||
    private fun performAction(action: AnAction) {
 | 
					      )
 | 
				
			||||||
      ActionManager.getInstance().tryToExecute(action, ActionCommand.getInputEvent(null), null, null, true)
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private fun performAction(action: AnAction) = ActionManager.getInstance()
 | 
				
			||||||
 | 
					      .tryToExecute(action, ActionCommand.getInputEvent(null), null, null, true)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										64
									
								
								src/main/kotlin/org/acejump/action/TagScroller.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								src/main/kotlin/org/acejump/action/TagScroller.kt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,64 @@
 | 
				
			|||||||
 | 
					package org.acejump.action
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.intellij.openapi.editor.*
 | 
				
			||||||
 | 
					import org.acejump.*
 | 
				
			||||||
 | 
					import org.acejump.search.SearchProcessor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					internal class TagScroller(private val editor: Editor, private val searchProcessor: SearchProcessor) {
 | 
				
			||||||
 | 
					  fun scroll(forward: Boolean = true): Boolean {
 | 
				
			||||||
 | 
					    val position = if (forward) findNextPosition() else findPreviousPosition()
 | 
				
			||||||
 | 
					    return if (position != null) true.also { scrollTo(position) } else false
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private fun scrollTo(position: LogicalPosition) = editor.run {
 | 
				
			||||||
 | 
					    scrollingModel.disableAnimation()
 | 
				
			||||||
 | 
					    scrollingModel.scrollTo(position, ScrollType.CENTER)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val firstInView = textMatches.first { it in editor.getView() }
 | 
				
			||||||
 | 
					    val horizontalOffset = offsetToLogicalPosition(firstInView).column
 | 
				
			||||||
 | 
					    if (horizontalOffset > scrollingModel.visibleArea.width)
 | 
				
			||||||
 | 
					      scrollingModel.scrollHorizontally(horizontalOffset)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  val textMatches by lazy { searchProcessor.results[editor]!! }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private fun findPreviousPosition(): LogicalPosition? {
 | 
				
			||||||
 | 
					    val prevIndex = textMatches.toList().dropLastWhile { it > editor.getView().first }
 | 
				
			||||||
 | 
					      .lastOrNull() ?: textMatches.lastOrNull() ?: return null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val prevLineNum = editor.offsetToLogicalPosition(prevIndex).line
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Try to capture as many previous results as will fit in a screenful
 | 
				
			||||||
 | 
					    fun maximizeCoverageOfPreviousOccurrence(): LogicalPosition {
 | 
				
			||||||
 | 
					      val minVisibleLine = prevLineNum - editor.getScreenHeight()
 | 
				
			||||||
 | 
					      val firstVisibleIndex = editor.getLineStartOffset(minVisibleLine)
 | 
				
			||||||
 | 
					      val firstIndex = textMatches.dropWhile { it < firstVisibleIndex }.first()
 | 
				
			||||||
 | 
					      return editor.offsetCenter(firstIndex, prevIndex)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return maximizeCoverageOfPreviousOccurrence()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Returns the center of the next set of results that will fit in the editor.
 | 
				
			||||||
 | 
					   * [textMatches] must be sorted prior to using Scroller. If [textMatches] have
 | 
				
			||||||
 | 
					   * not previously been sorted, the result of calling this method is undefined.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private fun findNextPosition(): LogicalPosition? {
 | 
				
			||||||
 | 
					    val nextIndex = textMatches.dropWhile { it <= editor.getView().last }
 | 
				
			||||||
 | 
					      .firstOrNull() ?: textMatches.firstOrNull() ?: return null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val nextLineNum = editor.offsetToLogicalPosition(nextIndex).line
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Try to capture as many subsequent results as will fit in a screenful
 | 
				
			||||||
 | 
					    fun maximizeCoverageOfNextOccurrence(): LogicalPosition {
 | 
				
			||||||
 | 
					      val maxVisibleLine = nextLineNum + editor.getScreenHeight()
 | 
				
			||||||
 | 
					      val lastVisibleIndex = editor.getLineEndOffset(maxVisibleLine, true)
 | 
				
			||||||
 | 
					      val lastIndex = textMatches.toList().dropLastWhile { it > lastVisibleIndex }.last()
 | 
				
			||||||
 | 
					      return editor.offsetCenter(nextIndex, lastIndex)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return maximizeCoverageOfNextOccurrence()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,9 +1,10 @@
 | 
				
			|||||||
package org.acejump.action
 | 
					package org.acejump.action
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.*
 | 
				
			||||||
import com.intellij.openapi.editor.ScrollType
 | 
					import com.intellij.openapi.editor.ScrollType.*
 | 
				
			||||||
import com.intellij.openapi.editor.SelectionModel
 | 
					import org.acejump.*
 | 
				
			||||||
import org.acejump.search.SearchProcessor
 | 
					import org.acejump.search.SearchProcessor
 | 
				
			||||||
 | 
					import org.acejump.search.Tag
 | 
				
			||||||
import kotlin.math.abs
 | 
					import kotlin.math.abs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@@ -11,63 +12,59 @@ import kotlin.math.abs
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
internal class TagVisitor(private val editor: Editor, private val searchProcessor: SearchProcessor, private val tagJumper: TagJumper) {
 | 
					internal class TagVisitor(private val editor: Editor, private val searchProcessor: SearchProcessor, private val tagJumper: TagJumper) {
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Places caret at the closest tag following the caret position, according to the rules of the current jump mode (see [TagJumper.visit]).
 | 
					   * Places caret at the closest tag following the caret position, according
 | 
				
			||||||
 | 
					   * to the rules of the current jump mode (see [TagJumper.visit]).
 | 
				
			||||||
   * If the caret is at or past the last tag, it moves to the first tag instead.
 | 
					   * If the caret is at or past the last tag, it moves to the first tag instead.
 | 
				
			||||||
   * If there is only one tag, it immediately performs the jump action as described in [TagJumper.jump].
 | 
					   * If there is only one tag, it immediately performs the jump action as described in [TagJumper.jump].
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun visitNext(): Boolean {
 | 
					  fun visitNext(): Boolean =
 | 
				
			||||||
    return visit(SelectionModel::getSelectionEnd) { if (it < 0) -it - 1 else it + 1 }
 | 
					    visit(SelectionModel::getSelectionEnd) { if (it < 0) -it - 1 else it + 1 }
 | 
				
			||||||
  }
 | 
					
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Places caret at the closest tag preceding the caret position, according to the rules of the current jump mode (see [TagJumper.visit]).
 | 
					   * Places caret at the closest tag preceding the caret position, according to
 | 
				
			||||||
 | 
					   * the rules of the current jump mode (see [TagJumper.visit]).
 | 
				
			||||||
   * If the caret is at or before the first tag, it moves to the last tag instead.
 | 
					   * If the caret is at or before the first tag, it moves to the last tag instead.
 | 
				
			||||||
   * If there is only one tag, it immediately performs the jump action as described in [TagJumper.jump].
 | 
					   * If there is only one tag, it immediately performs the jump action as described in [TagJumper.jump].
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun visitPrevious(): Boolean {
 | 
					  fun visitPrevious(): Boolean =
 | 
				
			||||||
    return visit(SelectionModel::getSelectionStart) { if (it < 0) -it - 2 else it - 1 }
 | 
					    visit(SelectionModel::getSelectionStart) { if (it < 0) -it - 2 else it - 1 }
 | 
				
			||||||
  }
 | 
					
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Scrolls to the closest result to the caret.
 | 
					   * Scrolls to the closest result to the caret.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun scrollToClosest() {
 | 
					  fun scrollToClosest() {
 | 
				
			||||||
    val caret = editor.caretModel.offset
 | 
					    val caret = editor.caretModel.offset
 | 
				
			||||||
    val results = searchProcessor.results.takeUnless { it.isEmpty } ?: return
 | 
					    val results = searchProcessor.results[editor].takeUnless { it.isNullOrEmpty() } ?: return
 | 
				
			||||||
    val index = results.binarySearch(caret).let { if (it < 0) -it - 1 else it }
 | 
					    val index = results.binarySearch(caret).let { if (it < 0) -it - 1 else it }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    val targetOffset = listOfNotNull(
 | 
					    val targetOffset = listOfNotNull(
 | 
				
			||||||
      results.getOrNull(index - 1),
 | 
					      results.getOrNull(index - 1),
 | 
				
			||||||
      results.getOrNull(index)
 | 
					      results.getOrNull(index)
 | 
				
			||||||
    ).minBy {
 | 
					    ).minByOrNull { abs(it - caret) }
 | 
				
			||||||
      abs(it - caret)
 | 
					
 | 
				
			||||||
    }
 | 
					    if (targetOffset != null)
 | 
				
			||||||
    
 | 
					      editor.scrollingModel.scrollTo(editor.offsetToLogicalPosition(targetOffset), RELATIVE)
 | 
				
			||||||
    if (targetOffset != null) {
 | 
					 | 
				
			||||||
      editor.scrollingModel.scrollTo(editor.offsetToLogicalPosition(targetOffset), ScrollType.RELATIVE)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private inline fun visit(caretPosition: SelectionModel.() -> Int, indexModifier: (Int) -> Int): Boolean {
 | 
					  private inline fun visit(caretPosition: SelectionModel.() -> Int, indexModifier: (Int) -> Int): Boolean {
 | 
				
			||||||
    val results = searchProcessor.results.takeUnless { it.isEmpty } ?: return false
 | 
					    val results = searchProcessor.results[editor].takeUnless { it.isNullOrEmpty() } ?: return false
 | 
				
			||||||
    val nextIndex = indexModifier(results.binarySearch(caretPosition(editor.selectionModel)))
 | 
					    val nextIndex = indexModifier(results.binarySearch(caretPosition(editor.selectionModel)))
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    val targetOffset = results.getInt(when {
 | 
					    val targetOffset = results.getInt(
 | 
				
			||||||
      nextIndex < 0                 -> results.lastIndex
 | 
					      when {
 | 
				
			||||||
      nextIndex > results.lastIndex -> 0
 | 
					        nextIndex < 0 -> results.lastIndex
 | 
				
			||||||
      else                          -> nextIndex
 | 
					        nextIndex > results.lastIndex -> 0
 | 
				
			||||||
    })
 | 
					        else -> nextIndex
 | 
				
			||||||
    
 | 
					      }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    val onlyResult = results.size == 1
 | 
					    val onlyResult = results.size == 1
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (onlyResult) {
 | 
					    if (onlyResult) tagJumper.jump(Tag(editor, targetOffset), shiftMode = false, isCrossEditor = false)
 | 
				
			||||||
      tagJumper.jump(targetOffset, shiftMode = false)
 | 
					    else tagJumper.visit(Tag(editor, targetOffset))
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
    else {
 | 
					    editor.scrollingModel.scrollToCaret(RELATIVE)
 | 
				
			||||||
      tagJumper.visit(targetOffset)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    editor.scrollingModel.scrollToCaret(ScrollType.RELATIVE)
 | 
					 | 
				
			||||||
    return onlyResult
 | 
					    return onlyResult
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,40 +5,38 @@ import kotlin.math.max
 | 
				
			|||||||
import kotlin.math.min
 | 
					import kotlin.math.min
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Defines a (possibly) disjoint set of editor offsets that partitions the whole editor into two groups - offsets inside the range, and
 | 
					 * Defines a (possibly) disjoint set of editor offsets that partitions
 | 
				
			||||||
 | 
					 * the whole editor into two groups - offsets inside the range, and
 | 
				
			||||||
 * offsets outside the range.
 | 
					 * offsets outside the range.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
interface Boundaries {
 | 
					interface Boundaries {
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Returns a range of editor offsets, starting at the first offset in the boundary, and ending at the last offset in the boundary.
 | 
					   * Returns a range of editor offsets, starting at the first offset in the
 | 
				
			||||||
   * May include offsets outside the boundary, for ex. when the boundary is rectangular and the file has long lines which are only
 | 
					   * boundary, and ending at the last offset in the boundary. May include
 | 
				
			||||||
   * partially visible.
 | 
					   * offsets outside the boundary, for ex. when the boundary is rectangular
 | 
				
			||||||
 | 
					   * and the file has long lines which are only partially visible.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun getOffsetRange(editor: Editor, cache: EditorOffsetCache = EditorOffsetCache.Uncached): IntRange
 | 
					  fun getOffsetRange(editor: Editor, cache: EditorOffsetCache = EditorOffsetCache.Uncached): IntRange
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Returns whether the editor offset is included within the boundary.
 | 
					   * Returns whether the editor offset is included within the boundary.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache = EditorOffsetCache.Uncached): Boolean
 | 
					  fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache = EditorOffsetCache.Uncached): Boolean
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Creates a boundary so that an offset/range is within the boundary iff it is within both original boundaries.
 | 
					   * Creates a boundary so that an offset/range is within the boundary
 | 
				
			||||||
 | 
					   * iff it is within both original boundaries.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun intersection(other: Boundaries): Boundaries {
 | 
					  fun intersection(other: Boundaries): Boundaries =
 | 
				
			||||||
    if (this === other) {
 | 
					    if (this === other) this
 | 
				
			||||||
      return this
 | 
					    else object: Boundaries {
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    return object : Boundaries {
 | 
					 | 
				
			||||||
      override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
 | 
					      override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
 | 
				
			||||||
        val b1 = this@Boundaries.getOffsetRange(editor, cache)
 | 
					        val b1 = this@Boundaries.getOffsetRange(editor, cache)
 | 
				
			||||||
        val b2 = other.getOffsetRange(editor, cache)
 | 
					        val b2 = other.getOffsetRange(editor, cache)
 | 
				
			||||||
        return max(b1.first, b2.first)..min(b1.last, b2.last)
 | 
					        return max(b1.first, b2.first)..min(b1.last, b2.last)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
 | 
					      override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean =
 | 
				
			||||||
        return this@Boundaries.isOffsetInside(editor, offset, cache) && other.isOffsetInside(editor, offset, cache)
 | 
					        this@Boundaries.isOffsetInside(editor, offset, cache) && other.isOffsetInside(editor, offset, cache)
 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,86 +6,72 @@ import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
 | 
				
			|||||||
import java.awt.Point
 | 
					import java.awt.Point
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Optionally caches slow operations of (1) retrieving the currently visible editor area, and (2) converting between editor offsets and
 | 
					 * Optionally caches slow operations of (1) retrieving the currently
 | 
				
			||||||
 | 
					 * visible editor area, and (2) converting between editor offsets and
 | 
				
			||||||
 * pixel coordinates.
 | 
					 * pixel coordinates.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * To avoid unnecessary overhead, there is no automatic detection of when the editor, its contents, or its visible area has changed, so the
 | 
					 * To avoid unnecessary overhead, there is no automatic detection of when
 | 
				
			||||||
 * cache must only be used for a single rendered frame of a single [Editor].
 | 
					 * the editor, its contents, or its visible area has changed, so the cache
 | 
				
			||||||
 | 
					 * must only be used for a single rendered frame of a single [Editor].
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
sealed class EditorOffsetCache {
 | 
					sealed class EditorOffsetCache {
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Returns the top left and bottom right points of the visible area rectangle.
 | 
					   * Returns the top left and bottom right points of the visible area rectangle.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  abstract fun visibleArea(editor: Editor): Pair<Point, Point>
 | 
					  abstract fun visibleArea(editor: Editor): Pair<Point, Point>
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Returns the editor offset at the provided pixel coordinate.
 | 
					   * Returns the editor offset at the provided pixel coordinate.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  abstract fun xyToOffset(editor: Editor, pos: Point): Int
 | 
					  abstract fun xyToOffset(editor: Editor, pos: Point): Int
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Returns the top left pixel coordinate of the character at the provided editor offset.
 | 
					   * Returns the top left pixel coordinate of the character at the provided editor offset.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  abstract fun offsetToXY(editor: Editor, offset: Int): Point
 | 
					  abstract fun offsetToXY(editor: Editor, offset: Int): Point
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  companion object {
 | 
					  companion object {
 | 
				
			||||||
    fun new(): EditorOffsetCache {
 | 
					    fun new(): EditorOffsetCache = Cache()
 | 
				
			||||||
      return Cache()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private class Cache : EditorOffsetCache() {
 | 
					  private class Cache: EditorOffsetCache() {
 | 
				
			||||||
    private var visibleArea: Pair<Point, Point>? = null
 | 
					    private var visibleArea: Pair<Point, Point>? = null
 | 
				
			||||||
    private val pointToOffset = Object2IntOpenHashMap<Point>().apply { defaultReturnValue(-1) }
 | 
					    private val pointToOffset = Object2IntOpenHashMap<Point>().apply { defaultReturnValue(-1) }
 | 
				
			||||||
    private val offsetToPoint = Int2ObjectOpenHashMap<Point>()
 | 
					    private val offsetToPoint = Int2ObjectOpenHashMap<Point>()
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    override fun visibleArea(editor: Editor): Pair<Point, Point> {
 | 
					    override fun visibleArea(editor: Editor): Pair<Point, Point> =
 | 
				
			||||||
      return visibleArea ?: Uncached.visibleArea(editor).also { visibleArea = it }
 | 
					      visibleArea ?: Uncached.visibleArea(editor).also { visibleArea = it }
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
    
 | 
					    override fun xyToOffset(editor: Editor, pos: Point): Int =
 | 
				
			||||||
    override fun xyToOffset(editor: Editor, pos: Point): Int {
 | 
					      pointToOffset.getInt(pos).let { offset ->
 | 
				
			||||||
      val offset = pointToOffset.getInt(pos)
 | 
					        if (offset != -1) offset
 | 
				
			||||||
      
 | 
					        else Uncached.xyToOffset(editor, pos).also {
 | 
				
			||||||
      if (offset != -1) {
 | 
					          @Suppress("ReplacePutWithAssignment")
 | 
				
			||||||
        return offset
 | 
					          pointToOffset.put(pos, it)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      return Uncached.xyToOffset(editor, pos).also {
 | 
					    override fun offsetToXY(editor: Editor, offset: Int) =
 | 
				
			||||||
        @Suppress("ReplacePutWithAssignment")
 | 
					      offsetToPoint.get(offset) ?: Uncached.offsetToXY(editor, offset).also {
 | 
				
			||||||
        pointToOffset.put(pos, it)
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    override fun offsetToXY(editor: Editor, offset: Int): Point {
 | 
					 | 
				
			||||||
      val pos = offsetToPoint.get(offset)
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      if (pos != null) {
 | 
					 | 
				
			||||||
        return pos
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      return Uncached.offsetToXY(editor, offset).also {
 | 
					 | 
				
			||||||
        @Suppress("ReplacePutWithAssignment")
 | 
					        @Suppress("ReplacePutWithAssignment")
 | 
				
			||||||
        offsetToPoint.put(offset, it)
 | 
					        offsetToPoint.put(offset, it)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  object Uncached : EditorOffsetCache() {
 | 
					  object Uncached: EditorOffsetCache() {
 | 
				
			||||||
    override fun visibleArea(editor: Editor): Pair<Point, Point> {
 | 
					    override fun visibleArea(editor: Editor): Pair<Point, Point> =
 | 
				
			||||||
      val visibleRect = editor.scrollingModel.visibleArea
 | 
					      editor.scrollingModel.visibleArea.let { visibleRect ->
 | 
				
			||||||
      
 | 
					        Pair(
 | 
				
			||||||
      return Pair(
 | 
					          visibleRect.location, visibleRect.location.apply {
 | 
				
			||||||
        visibleRect.location,
 | 
					            translate(visibleRect.width, visibleRect.height)
 | 
				
			||||||
        visibleRect.location.apply { translate(visibleRect.width, visibleRect.height) }
 | 
					          }
 | 
				
			||||||
      )
 | 
					        )
 | 
				
			||||||
    }
 | 
					      }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    override fun xyToOffset(editor: Editor, pos: Point): Int {
 | 
					    override fun xyToOffset(editor: Editor, pos: Point): Int =
 | 
				
			||||||
      return editor.logicalPositionToOffset(editor.xyToLogicalPosition(pos))
 | 
					      editor.logicalPositionToOffset(editor.xyToLogicalPosition(pos))
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
    
 | 
					    override fun offsetToXY(editor: Editor, offset: Int): Point =
 | 
				
			||||||
    override fun offsetToXY(editor: Editor, offset: Int): Point {
 | 
					      editor.offsetToXY(offset, true, false)
 | 
				
			||||||
      return editor.offsetToXY(offset, true, false)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,13 +4,11 @@ import com.intellij.openapi.editor.Editor
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
enum class StandardBoundaries : Boundaries {
 | 
					enum class StandardBoundaries : Boundaries {
 | 
				
			||||||
  WHOLE_FILE {
 | 
					  WHOLE_FILE {
 | 
				
			||||||
    override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
 | 
					    override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache) =
 | 
				
			||||||
      return 0 until editor.document.textLength
 | 
					      0 until editor.document.textLength
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
 | 
					    override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache) =
 | 
				
			||||||
      return offset in (0 until editor.document.textLength)
 | 
					      offset in (0 until editor.document.textLength)
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  VISIBLE_ON_SCREEN {
 | 
					  VISIBLE_ON_SCREEN {
 | 
				
			||||||
@@ -23,16 +21,15 @@ enum class StandardBoundaries : Boundaries {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
 | 
					    override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
 | 
				
			||||||
      
 | 
					      // If we are not using a cache, calling getOffsetRange will cause
 | 
				
			||||||
      // If we are not using a cache, calling getOffsetRange will cause additional 1-2 pixel coordinate -> offset lookups, which is a lot
 | 
					      // additional 1-2 pixel coordinate -> offset lookups, which is a lot
 | 
				
			||||||
      // more expensive than one lookup compared against the visible area.
 | 
					      // more expensive than one lookup compared against the visible area.
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // However, if we are using a cache, it's likely that the topmost and bottommost positions are already cached whereas the provided
 | 
					      // However, if we are using a cache, it's likely that the topmost and
 | 
				
			||||||
      // offset isn't, so we save a lookup for every offset outside the range.
 | 
					      // bottommost positions are already cached whereas the provided offset
 | 
				
			||||||
 | 
					      // isn't, so we save a lookup for every offset outside the range.
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      if (cache !== EditorOffsetCache.Uncached && offset !in getOffsetRange(editor, cache)) {
 | 
					      if (cache !== EditorOffsetCache.Uncached && offset !in getOffsetRange(editor, cache)) return false
 | 
				
			||||||
        return false
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      val (topLeft, bottomRight) = cache.visibleArea(editor)
 | 
					      val (topLeft, bottomRight) = cache.visibleArea(editor)
 | 
				
			||||||
      val pos = cache.offsetToXY(editor, offset)
 | 
					      val pos = cache.offsetToXY(editor, offset)
 | 
				
			||||||
@@ -44,22 +41,18 @@ enum class StandardBoundaries : Boundaries {
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  BEFORE_CARET {
 | 
					  BEFORE_CARET {
 | 
				
			||||||
    override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
 | 
					    override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache) =
 | 
				
			||||||
      return 0..(editor.caretModel.offset)
 | 
					      0..(editor.caretModel.offset)
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
 | 
					    override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean =
 | 
				
			||||||
      return offset <= editor.caretModel.offset
 | 
					      offset <= editor.caretModel.offset
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  AFTER_CARET {
 | 
					  AFTER_CARET {
 | 
				
			||||||
    override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
 | 
					    override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache) =
 | 
				
			||||||
      return editor.caretModel.offset until editor.document.textLength
 | 
					      editor.caretModel.offset until editor.document.textLength
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
 | 
					    override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean =
 | 
				
			||||||
      return offset >= editor.caretModel.offset
 | 
					      offset >= editor.caretModel.offset
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,34 +7,36 @@ import com.intellij.openapi.components.Storage
 | 
				
			|||||||
import org.acejump.input.KeyLayoutCache
 | 
					import org.acejump.input.KeyLayoutCache
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Ensures consistiency between [AceSettings] and [AceSettingsPanel]. Persists the state of the AceJump IDE settings across IDE restarts.
 | 
					 * Ensures consistency between [AceSettings] and [AceSettingsPanel].
 | 
				
			||||||
 | 
					 * Persists the state of the AceJump IDE settings across IDE restarts.
 | 
				
			||||||
 * [https://www.jetbrains.org/intellij/sdk/docs/basics/persisting_state_of_components.html]
 | 
					 * [https://www.jetbrains.org/intellij/sdk/docs/basics/persisting_state_of_components.html]
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@State(name = "AceConfig", storages = [(Storage("\$APP_CONFIG\$/AceJump.xml"))])
 | 
					@State(name = "AceConfig", storages = [(Storage("\$APP_CONFIG\$/AceJump.xml"))])
 | 
				
			||||||
class AceConfig : PersistentStateComponent<AceSettings> {
 | 
					class AceConfig: PersistentStateComponent<AceSettings> {
 | 
				
			||||||
  private var aceSettings = AceSettings()
 | 
					  private var aceSettings = AceSettings()
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  companion object {
 | 
					  companion object {
 | 
				
			||||||
    val settings
 | 
					    val settings get() = ServiceManager.getService(AceConfig::class.java).aceSettings
 | 
				
			||||||
      get() = ServiceManager.getService(AceConfig::class.java).aceSettings
 | 
					
 | 
				
			||||||
    
 | 
					    // @formatter:off
 | 
				
			||||||
    val layout get() = settings.layout
 | 
					    val layout get()              = settings.layout
 | 
				
			||||||
    val cycleModes get() = settings.let { arrayOf(it.cycleMode1, it.cycleMode2, it.cycleMode3, it.cycleMode4) }
 | 
					    val cycleModes get()          = settings.let { arrayOf(it.cycleMode1, it.cycleMode2, it.cycleMode3, it.cycleMode4) }
 | 
				
			||||||
    val minQueryLength get() = settings.minQueryLength
 | 
					    val minQueryLength get()      = settings.minQueryLength
 | 
				
			||||||
    val jumpModeColor get() = settings.jumpModeColor
 | 
					    val jumpModeColor get()       = settings.jumpModeColor
 | 
				
			||||||
    val jumpEndModeColor get() = settings.jumpEndModeColor
 | 
					    val jumpEndModeColor get()    = settings.jumpEndModeColor
 | 
				
			||||||
    val targetModeColor get() = settings.targetModeColor
 | 
					    val targetModeColor get()     = settings.targetModeColor
 | 
				
			||||||
    val definitionModeColor get() = settings.definitionModeColor
 | 
					    val definitionModeColor get() = settings.definitionModeColor
 | 
				
			||||||
    val textHighlightColor get() = settings.textHighlightColor
 | 
					    val textHighlightColor get()  = settings.textHighlightColor
 | 
				
			||||||
    val tagForegroundColor get() = settings.tagForegroundColor
 | 
					    val tagForegroundColor get()  = settings.tagForegroundColor
 | 
				
			||||||
    val tagBackgroundColor get() = settings.tagBackgroundColor
 | 
					    val tagBackgroundColor get()  = settings.tagBackgroundColor
 | 
				
			||||||
    val searchWholeFile get() = settings.searchWholeFile
 | 
					    val searchWholeFile get()     = settings.searchWholeFile
 | 
				
			||||||
 | 
					    val mapToASCII get()        = settings.mapToASCII
 | 
				
			||||||
 | 
					    val showSearchNotification get()          = settings.showSearchNotification
 | 
				
			||||||
 | 
					    // @formatter:on
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  override fun getState(): AceSettings {
 | 
					  override fun getState() = aceSettings
 | 
				
			||||||
    return aceSettings
 | 
					
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  override fun loadState(state: AceSettings) {
 | 
					  override fun loadState(state: AceSettings) {
 | 
				
			||||||
    aceSettings = state
 | 
					    aceSettings = state
 | 
				
			||||||
    KeyLayoutCache.reset(state)
 | 
					    KeyLayoutCache.reset(state)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,13 +4,13 @@ import com.intellij.openapi.options.Configurable
 | 
				
			|||||||
import org.acejump.config.AceConfig.Companion.settings
 | 
					import org.acejump.config.AceConfig.Companion.settings
 | 
				
			||||||
import org.acejump.input.KeyLayoutCache
 | 
					import org.acejump.input.KeyLayoutCache
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AceConfigurable : Configurable {
 | 
					class AceConfigurable: Configurable {
 | 
				
			||||||
  private val panel by lazy(::AceSettingsPanel)
 | 
					  private val panel by lazy(::AceSettingsPanel)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  override fun getDisplayName() = "AceJump"
 | 
					  override fun getDisplayName() = "AceJump"
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  override fun createComponent() = panel.rootPanel
 | 
					  override fun createComponent() = panel.rootPanel
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  override fun isModified() =
 | 
					  override fun isModified() =
 | 
				
			||||||
    panel.allowedChars != settings.allowedChars ||
 | 
					    panel.allowedChars != settings.allowedChars ||
 | 
				
			||||||
      panel.keyboardLayout != settings.layout ||
 | 
					      panel.keyboardLayout != settings.layout ||
 | 
				
			||||||
@@ -26,8 +26,10 @@ class AceConfigurable : Configurable {
 | 
				
			|||||||
      panel.textHighlightColor != settings.textHighlightColor ||
 | 
					      panel.textHighlightColor != settings.textHighlightColor ||
 | 
				
			||||||
      panel.tagForegroundColor != settings.tagForegroundColor ||
 | 
					      panel.tagForegroundColor != settings.tagForegroundColor ||
 | 
				
			||||||
      panel.tagBackgroundColor != settings.tagBackgroundColor ||
 | 
					      panel.tagBackgroundColor != settings.tagBackgroundColor ||
 | 
				
			||||||
      panel.searchWholeFile != settings.searchWholeFile
 | 
					      panel.searchWholeFile != settings.searchWholeFile ||
 | 
				
			||||||
  
 | 
					      panel.mapToASCII != settings.mapToASCII ||
 | 
				
			||||||
 | 
					      panel.showSearchNotification != settings.showSearchNotification
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun apply() {
 | 
					  override fun apply() {
 | 
				
			||||||
    settings.allowedChars = panel.allowedChars
 | 
					    settings.allowedChars = panel.allowedChars
 | 
				
			||||||
    settings.layout = panel.keyboardLayout
 | 
					    settings.layout = panel.keyboardLayout
 | 
				
			||||||
@@ -44,8 +46,10 @@ class AceConfigurable : Configurable {
 | 
				
			|||||||
    panel.tagForegroundColor?.let { settings.tagForegroundColor = it }
 | 
					    panel.tagForegroundColor?.let { settings.tagForegroundColor = it }
 | 
				
			||||||
    panel.tagBackgroundColor?.let { settings.tagBackgroundColor = it }
 | 
					    panel.tagBackgroundColor?.let { settings.tagBackgroundColor = it }
 | 
				
			||||||
    settings.searchWholeFile = panel.searchWholeFile
 | 
					    settings.searchWholeFile = panel.searchWholeFile
 | 
				
			||||||
 | 
					    settings.mapToASCII = panel.mapToASCII
 | 
				
			||||||
 | 
					    settings.showSearchNotification = panel.showSearchNotification
 | 
				
			||||||
    KeyLayoutCache.reset(settings)
 | 
					    KeyLayoutCache.reset(settings)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  override fun reset() = panel.reset(settings)
 | 
					  override fun reset() = panel.reset(settings)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
package org.acejump.config
 | 
					package org.acejump.config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.intellij.util.xmlb.Converter
 | 
				
			||||||
import com.intellij.util.xmlb.annotations.OptionTag
 | 
					import com.intellij.util.xmlb.annotations.OptionTag
 | 
				
			||||||
import org.acejump.input.JumpMode
 | 
					import org.acejump.input.JumpMode
 | 
				
			||||||
import org.acejump.input.KeyLayout
 | 
					import org.acejump.input.KeyLayout
 | 
				
			||||||
@@ -10,31 +11,40 @@ data class AceSettings(
 | 
				
			|||||||
  var layout: KeyLayout = QWERTY,
 | 
					  var layout: KeyLayout = QWERTY,
 | 
				
			||||||
  var allowedChars: String = layout.allChars,
 | 
					  var allowedChars: String = layout.allChars,
 | 
				
			||||||
  var cycleMode1: JumpMode = JumpMode.JUMP,
 | 
					  var cycleMode1: JumpMode = JumpMode.JUMP,
 | 
				
			||||||
  var cycleMode2: JumpMode = JumpMode.DEFINE,
 | 
					  var cycleMode2: JumpMode = JumpMode.DECLARATION,
 | 
				
			||||||
  var cycleMode3: JumpMode = JumpMode.TARGET,
 | 
					  var cycleMode3: JumpMode = JumpMode.TARGET,
 | 
				
			||||||
  var cycleMode4: JumpMode = JumpMode.JUMP_END,
 | 
					  var cycleMode4: JumpMode = JumpMode.JUMP_END,
 | 
				
			||||||
  var minQueryLength: Int = 1,
 | 
					  var minQueryLength: Int = 1,
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  @OptionTag("jumpModeRGB", converter = ColorConverter::class)
 | 
					  @OptionTag("jumpModeRGB", converter = ColorConverter::class)
 | 
				
			||||||
  var jumpModeColor: Color = Color(0xFFFFFF),
 | 
					  var jumpModeColor: Color = Color(0xFFFFFF),
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  @OptionTag("jumpEndModeRGB", converter = ColorConverter::class)
 | 
					  @OptionTag("jumpEndModeRGB", converter = ColorConverter::class)
 | 
				
			||||||
  var jumpEndModeColor: Color = Color(0x33E78A),
 | 
					  var jumpEndModeColor: Color = Color(0x33E78A),
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  @OptionTag("targetModeRGB", converter = ColorConverter::class)
 | 
					  @OptionTag("targetModeRGB", converter = ColorConverter::class)
 | 
				
			||||||
  var targetModeColor: Color = Color(0xFFB700),
 | 
					  var targetModeColor: Color = Color(0xFFB700),
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  @OptionTag("definitionModeRGB", converter = ColorConverter::class)
 | 
					  @OptionTag("definitionModeRGB", converter = ColorConverter::class)
 | 
				
			||||||
  var definitionModeColor: Color = Color(0x6FC5FF),
 | 
					  var definitionModeColor: Color = Color(0x6FC5FF),
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  @OptionTag("textHighlightRGB", converter = ColorConverter::class)
 | 
					  @OptionTag("textHighlightRGB", converter = ColorConverter::class)
 | 
				
			||||||
  var textHighlightColor: Color = Color(0x394B58),
 | 
					  var textHighlightColor: Color = Color(0x394B58),
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  @OptionTag("tagForegroundRGB", converter = ColorConverter::class)
 | 
					  @OptionTag("tagForegroundRGB", converter = ColorConverter::class)
 | 
				
			||||||
  var tagForegroundColor: Color = Color(0xFFFFFF),
 | 
					  var tagForegroundColor: Color = Color(0xFFFFFF),
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  @OptionTag("tagBackgroundRGB", converter = ColorConverter::class)
 | 
					  @OptionTag("tagBackgroundRGB", converter = ColorConverter::class)
 | 
				
			||||||
  var tagBackgroundColor: Color = Color(0x008299),
 | 
					  var tagBackgroundColor: Color = Color(0x008299),
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  var searchWholeFile: Boolean = true
 | 
					  var searchWholeFile: Boolean = true,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  var mapToASCII : Boolean = false,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  var showSearchNotification : Boolean = false
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					internal class ColorConverter: Converter<Color>() {
 | 
				
			||||||
 | 
					  override fun toString(value: Color) = value.rgb.toString()
 | 
				
			||||||
 | 
					  override fun fromString(value: String) = value.toIntOrNull()?.let(::Color)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,9 @@ internal class AceSettingsPanel {
 | 
				
			|||||||
  private val tagForegroundColorWheel = ColorPanel()
 | 
					  private val tagForegroundColorWheel = ColorPanel()
 | 
				
			||||||
  private val tagBackgroundColorWheel = ColorPanel()
 | 
					  private val tagBackgroundColorWheel = ColorPanel()
 | 
				
			||||||
  private val searchWholeFileCheckBox = JBCheckBox()
 | 
					  private val searchWholeFileCheckBox = JBCheckBox()
 | 
				
			||||||
  
 | 
					  private val mapToASCIICheckBox = JBCheckBox()
 | 
				
			||||||
 | 
					  private val showSearchNotificationCheckBox = JBCheckBox()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  init {
 | 
					  init {
 | 
				
			||||||
    tagCharsField.apply { font = Font("monospaced", font.style, font.size) }
 | 
					    tagCharsField.apply { font = Font("monospaced", font.style, font.size) }
 | 
				
			||||||
    keyboardLayoutArea.apply { font = Font("monospaced", font.style, font.size) }
 | 
					    keyboardLayoutArea.apply { font = Font("monospaced", font.style, font.size) }
 | 
				
			||||||
@@ -50,28 +52,28 @@ internal class AceSettingsPanel {
 | 
				
			|||||||
    cycleModeCombo3.setupEnumItems { cycleMode3 = it }
 | 
					    cycleModeCombo3.setupEnumItems { cycleMode3 = it }
 | 
				
			||||||
    cycleModeCombo4.setupEnumItems { cycleMode4 = it }
 | 
					    cycleModeCombo4.setupEnumItems { cycleMode4 = it }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  internal val rootPanel: JPanel = panel {
 | 
					  internal val rootPanel: JPanel = panel {
 | 
				
			||||||
    fun Cell.short(component: JComponent) = component(growPolicy = SHORT_TEXT)
 | 
					    fun Cell.short(component: JComponent) = component(growPolicy = SHORT_TEXT)
 | 
				
			||||||
    fun Cell.medium(component: JComponent) = component(growPolicy = MEDIUM_TEXT)
 | 
					    fun Cell.medium(component: JComponent) = component(growPolicy = MEDIUM_TEXT)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    titledRow("Characters and Layout") {
 | 
					    titledRow("Characters and Layout") {
 | 
				
			||||||
      row("Allowed characters in tags:") { medium(tagCharsField) }
 | 
					      row("Allowed characters in tags:") { medium(tagCharsField) }
 | 
				
			||||||
      row("Keyboard layout:") { short(keyboardLayoutCombo) }
 | 
					      row("Keyboard layout:") { short(keyboardLayoutCombo) }
 | 
				
			||||||
      row("Keyboard design:") { short(keyboardLayoutArea) }
 | 
					      row("Keyboard design:") { short(keyboardLayoutArea) }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    titledRow("Modes") {
 | 
					    titledRow("Modes") {
 | 
				
			||||||
      row("Cycle order:") {
 | 
					      row("Cycle order:") { cell { cycleModeCombo1() } }
 | 
				
			||||||
        cell(isVerticalFlow = false, isFullWidth = false) {
 | 
					      row("") {
 | 
				
			||||||
          cycleModeCombo1()
 | 
					        cell(isVerticalFlow = true) {
 | 
				
			||||||
          cycleModeCombo2()
 | 
					          cycleModeCombo2()
 | 
				
			||||||
          cycleModeCombo3()
 | 
					          cycleModeCombo3()
 | 
				
			||||||
          cycleModeCombo4()
 | 
					          cycleModeCombo4()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    titledRow("Colors") {
 | 
					    titledRow("Colors") {
 | 
				
			||||||
      row("Jump mode caret background:") { short(jumpModeColorWheel) }
 | 
					      row("Jump mode caret background:") { short(jumpModeColorWheel) }
 | 
				
			||||||
      row("Jump to End mode caret background:") { short(jumpEndModeColorWheel) }
 | 
					      row("Jump to End mode caret background:") { short(jumpEndModeColorWheel) }
 | 
				
			||||||
@@ -81,13 +83,19 @@ internal class AceSettingsPanel {
 | 
				
			|||||||
      row("Tag foreground:") { short(tagForegroundColorWheel) }
 | 
					      row("Tag foreground:") { short(tagForegroundColorWheel) }
 | 
				
			||||||
      row("Tag background:") { short(tagBackgroundColorWheel) }
 | 
					      row("Tag background:") { short(tagBackgroundColorWheel) }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    titledRow("Behavior") {
 | 
					    titledRow("Behavior") {
 | 
				
			||||||
      row { short(searchWholeFileCheckBox.apply { text = "Search whole file" }) }
 | 
					      row { short(searchWholeFileCheckBox.apply { text = "Search whole file" }) }
 | 
				
			||||||
      row("Minimum typed characters (1-10):") { short(minQueryLengthField) }
 | 
					      row("Minimum typed characters (1-10):") { short(minQueryLengthField) }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    titledRow("Language Settings") {
 | 
				
			||||||
 | 
					      row { short(mapToASCIICheckBox.apply { text = "Map unicode to ASCII" }) }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    titledRow("Visual") {
 | 
				
			||||||
 | 
					      row { short(showSearchNotificationCheckBox.apply { text = "Show hint with search text" }) }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  // Property-to-property delegation: https://stackoverflow.com/q/45074596/1772342
 | 
					  // Property-to-property delegation: https://stackoverflow.com/q/45074596/1772342
 | 
				
			||||||
  internal var allowedChars by tagCharsField
 | 
					  internal var allowedChars by tagCharsField
 | 
				
			||||||
  internal var keyboardLayout by keyboardLayoutCombo
 | 
					  internal var keyboardLayout by keyboardLayoutCombo
 | 
				
			||||||
@@ -105,11 +113,15 @@ internal class AceSettingsPanel {
 | 
				
			|||||||
  internal var tagForegroundColor by tagForegroundColorWheel
 | 
					  internal var tagForegroundColor by tagForegroundColorWheel
 | 
				
			||||||
  internal var tagBackgroundColor by tagBackgroundColorWheel
 | 
					  internal var tagBackgroundColor by tagBackgroundColorWheel
 | 
				
			||||||
  internal var searchWholeFile by searchWholeFileCheckBox
 | 
					  internal var searchWholeFile by searchWholeFileCheckBox
 | 
				
			||||||
  
 | 
					  internal var mapToASCII by mapToASCIICheckBox
 | 
				
			||||||
 | 
					  internal var showSearchNotification by showSearchNotificationCheckBox
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  internal var minQueryLengthInt
 | 
					  internal var minQueryLengthInt
 | 
				
			||||||
    get() = minQueryLength.toIntOrNull()?.coerceIn(1, 10)
 | 
					    get() = minQueryLength.toIntOrNull()?.coerceIn(1, 10)
 | 
				
			||||||
    set(value) { minQueryLength = value.toString() }
 | 
					    set(value) {
 | 
				
			||||||
  
 | 
					      minQueryLength = value.toString()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun reset(settings: AceSettings) {
 | 
					  fun reset(settings: AceSettings) {
 | 
				
			||||||
    allowedChars = settings.allowedChars
 | 
					    allowedChars = settings.allowedChars
 | 
				
			||||||
    keyboardLayout = settings.layout
 | 
					    keyboardLayout = settings.layout
 | 
				
			||||||
@@ -126,23 +138,25 @@ internal class AceSettingsPanel {
 | 
				
			|||||||
    tagForegroundColor = settings.tagForegroundColor
 | 
					    tagForegroundColor = settings.tagForegroundColor
 | 
				
			||||||
    tagBackgroundColor = settings.tagBackgroundColor
 | 
					    tagBackgroundColor = settings.tagBackgroundColor
 | 
				
			||||||
    searchWholeFile = settings.searchWholeFile
 | 
					    searchWholeFile = settings.searchWholeFile
 | 
				
			||||||
 | 
					    mapToASCII = settings.mapToASCII
 | 
				
			||||||
 | 
					    showSearchNotification = settings.showSearchNotification
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  // Removal pending support for https://youtrack.jetbrains.com/issue/KT-8575
 | 
					  // Removal pending support for https://youtrack.jetbrains.com/issue/KT-8575
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private operator fun JTextComponent.getValue(a: AceSettingsPanel, p: KProperty<*>) = text.toLowerCase()
 | 
					  private operator fun JTextComponent.getValue(a: AceSettingsPanel, p: KProperty<*>) = text.lowercase()
 | 
				
			||||||
  private operator fun JTextComponent.setValue(a: AceSettingsPanel, p: KProperty<*>, s: String) = setText(s)
 | 
					  private operator fun JTextComponent.setValue(a: AceSettingsPanel, p: KProperty<*>, s: String) = setText(s)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private operator fun ColorPanel.getValue(a: AceSettingsPanel, p: KProperty<*>) = selectedColor
 | 
					  private operator fun ColorPanel.getValue(a: AceSettingsPanel, p: KProperty<*>) = selectedColor
 | 
				
			||||||
  private operator fun ColorPanel.setValue(a: AceSettingsPanel, p: KProperty<*>, c: Color?) = setSelectedColor(c)
 | 
					  private operator fun ColorPanel.setValue(a: AceSettingsPanel, p: KProperty<*>, c: Color?) = setSelectedColor(c)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private operator fun JCheckBox.getValue(a: AceSettingsPanel, p: KProperty<*>) = isSelected
 | 
					  private operator fun JCheckBox.getValue(a: AceSettingsPanel, p: KProperty<*>) = isSelected
 | 
				
			||||||
  private operator fun JCheckBox.setValue(a: AceSettingsPanel, p: KProperty<*>, selected: Boolean) = setSelected(selected)
 | 
					  private operator fun JCheckBox.setValue(a: AceSettingsPanel, p: KProperty<*>, selected: Boolean) = setSelected(selected)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private operator fun <T> ComboBox<T>.getValue(a: AceSettingsPanel, p: KProperty<*>) = selectedItem as T
 | 
					  private inline operator fun <reified T> ComboBox<T>.getValue(a: AceSettingsPanel, p: KProperty<*>) = selectedItem as T
 | 
				
			||||||
  private operator fun <T> ComboBox<T>.setValue(a: AceSettingsPanel, p: KProperty<*>, item: T) = setSelectedItem(item)
 | 
					  private operator fun <T> ComboBox<T>.setValue(a: AceSettingsPanel, p: KProperty<*>, item: T) = setSelectedItem(item)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private inline fun <reified T : Enum<T>> ComboBox<T>.setupEnumItems(crossinline onChanged: (T) -> Unit) {
 | 
					  private inline fun <reified T: Enum<T>> ComboBox<T>.setupEnumItems(crossinline onChanged: (T) -> Unit) {
 | 
				
			||||||
    T::class.java.enumConstants.forEach(this::addItem)
 | 
					    T::class.java.enumConstants.forEach(this::addItem)
 | 
				
			||||||
    addActionListener { onChanged(selectedItem as T) }
 | 
					    addActionListener { onChanged(selectedItem as T) }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,14 +0,0 @@
 | 
				
			|||||||
package org.acejump.config
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.intellij.util.xmlb.Converter
 | 
					 | 
				
			||||||
import java.awt.Color
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
internal class ColorConverter : Converter<Color>() {
 | 
					 | 
				
			||||||
  override fun toString(value: Color): String {
 | 
					 | 
				
			||||||
    return value.rgb.toString()
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  override fun fromString(value: String): Color? {
 | 
					 | 
				
			||||||
    return value.toIntOrNull()?.let(::Color)
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -6,30 +6,31 @@ import com.intellij.openapi.editor.actionSystem.TypedAction
 | 
				
			|||||||
import com.intellij.openapi.editor.actionSystem.TypedActionHandler
 | 
					import com.intellij.openapi.editor.actionSystem.TypedActionHandler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * If at least one session exists, this listener redirects all characters, typed in [Editor]s with attached sessions, to the appropriate
 | 
					 * If at least one session exists, this listener redirects all characters
 | 
				
			||||||
 * sessions' own handlers.
 | 
					 * typed in [Editor]s with attached sessions to the appropriate sessions'
 | 
				
			||||||
 | 
					 * own handlers.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal object EditorKeyListener : TypedActionHandler {
 | 
					internal object EditorKeyListener: TypedActionHandler {
 | 
				
			||||||
  private val action = TypedAction.getInstance()
 | 
					  private val action = TypedAction.getInstance()
 | 
				
			||||||
  private val attached = mutableMapOf<Editor, TypedActionHandler>()
 | 
					  private val attached = mutableMapOf<Editor, TypedActionHandler>()
 | 
				
			||||||
  private var originalHandler: TypedActionHandler? = null
 | 
					  private var originalHandler: TypedActionHandler? = null
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  override fun execute(editor: Editor, charTyped: Char, dataContext: DataContext) {
 | 
					  override fun execute(editor: Editor, charTyped: Char, dataContext: DataContext) {
 | 
				
			||||||
    (attached[editor] ?: originalHandler ?: return).execute(editor, charTyped, dataContext)
 | 
					    (attached[editor] ?: originalHandler ?: return).execute(editor, charTyped, dataContext)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun attach(editor: Editor, callback: TypedActionHandler) {
 | 
					  fun attach(editor: Editor, callback: TypedActionHandler) {
 | 
				
			||||||
    if (attached.isEmpty()) {
 | 
					    if (attached.isEmpty()) {
 | 
				
			||||||
      originalHandler = action.rawHandler
 | 
					      originalHandler = action.rawHandler
 | 
				
			||||||
      action.setupRawHandler(this)
 | 
					      action.setupRawHandler(this)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    attached[editor] = callback
 | 
					    attached[editor] = callback
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun detach(editor: Editor) {
 | 
					  fun detach(editor: Editor) {
 | 
				
			||||||
    attached.remove(editor)
 | 
					    attached.remove(editor)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (attached.isEmpty()) {
 | 
					    if (attached.isEmpty()) {
 | 
				
			||||||
      originalHandler?.let(action::setupRawHandler)
 | 
					      originalHandler?.let(action::setupRawHandler)
 | 
				
			||||||
      originalHandler = null
 | 
					      originalHandler = null
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,57 +5,69 @@ import org.acejump.config.AceConfig
 | 
				
			|||||||
import java.awt.Color
 | 
					import java.awt.Color
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Describes modes that determine the behavior of a "jump" to a tag. Most modes have two variations:
 | 
					 * Describes modes that determine the behavior of a "jump" to a tag.
 | 
				
			||||||
 * - **Default jump** happens when jumping without holding the Shift key
 | 
					 * Most modes have two variations:
 | 
				
			||||||
 * - **Shift jump** happens when jumping while holding the Shift key
 | 
					 *   - **Default jump** happens when jumping without holding the Shift key
 | 
				
			||||||
 | 
					 *   - **Shift jump** happens when jumping while holding the Shift key
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
enum class JumpMode {
 | 
					enum class JumpMode {
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Default value at the start of a session. If the session does not get assigned a proper [JumpMode] by the time the user requests a jump,
 | 
					   * Default value at the start of a session. If the session does not get
 | 
				
			||||||
   * the results of the jump are undefined.
 | 
					   * assigned a proper [JumpMode] by the time the user requests a jump, the
 | 
				
			||||||
 | 
					   * results of the jump are undefined.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  DISABLED,
 | 
					  DISABLED,
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * On default jump, places the caret at the first character of the search query.
 | 
					   * On default jump, places the caret at the first character of the search
 | 
				
			||||||
   * On shift jump, does the above but also selects all text between the original and new caret positions.
 | 
					   * query. On shift jump, does the above but also selects all text between
 | 
				
			||||||
 | 
					   * the original and new caret positions.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  JUMP,
 | 
					  JUMP,
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * On default jump, places the caret at the end of a word. Word detection uses [Character.isJavaIdentifierPart] to count some special
 | 
					   * On default jump, places the caret at the end of a word. Word detection
 | 
				
			||||||
   * characters, such as underscores, as part of a word. If there is no word at the first character of the search query, then the caret is
 | 
					   * uses [Character.isJavaIdentifierPart] to count some special characters,
 | 
				
			||||||
   * placed after the last character of the search query.
 | 
					   * such as underscores, as part of a word. If there is no word at the first
 | 
				
			||||||
 | 
					   * character of the search query, then the caret is placed after the last
 | 
				
			||||||
 | 
					   * character of the search query.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * On shift jump, does the above but also selects all text between the original and new caret positions.
 | 
					   * On shift jump, does the above but also selects all text between
 | 
				
			||||||
 | 
					   * the original and new caret positions.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  JUMP_END,
 | 
					  JUMP_END,
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * On default jump, places the caret at the end of a word, and also selects the entire word. Word detection uses
 | 
					   * On default jump, places the caret at the end of a word, and also selects
 | 
				
			||||||
   * [Character.isJavaIdentifierPart] to count some special characters, such as underscores, as part of a word. If there is no word at the
 | 
					   * the entire word. Word detection uses [Character.isJavaIdentifierPart] to
 | 
				
			||||||
   * first character of the search query, then the caret is placed after the last character of the search query, and all text between the
 | 
					   * count some special characters, such as underscores, as part of a word.
 | 
				
			||||||
   * start and end of the search query is selected.
 | 
					   * If there is no word at the first character of the search query, then the
 | 
				
			||||||
 | 
					   * caret is placed after the last character of the search query, and all
 | 
				
			||||||
 | 
					   * text between the start and end of the search query is selected.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * On shift jump, does the above but also selects all text between the original caret position and the new selection, merging the
 | 
					   * On shift jump, does the above but also selects all text between the
 | 
				
			||||||
   * selections into one.
 | 
					   * start of the original caret position and the end of the new selection.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  TARGET,
 | 
					  TARGET,
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * On default jump, performs the Go To Declaration action, available via `Navigate | Declaration or Usages`.
 | 
					   * On default jump, performs the Go To Declaration action, available
 | 
				
			||||||
   * On shift jump, performs the Go To Type Declaration action, available via `Navigate | Type Declaration`.
 | 
					   * via `Navigate | Declaration or Usages`.
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
 | 
					   * On shift jump, performs the Go To Type Declaration action, available
 | 
				
			||||||
 | 
					   * via `Navigate | Type Declaration`.
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
   * Always places the caret at the first character of the search query.
 | 
					   * Always places the caret at the first character of the search query.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  DEFINE;
 | 
					  DECLARATION;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  val caretColor: Color
 | 
					  val caretColor: Color
 | 
				
			||||||
    get() = when (this) {
 | 
					    get() = when (this) {
 | 
				
			||||||
      JUMP     -> AceConfig.jumpModeColor
 | 
					      JUMP        -> AceConfig.jumpModeColor
 | 
				
			||||||
      JUMP_END -> AceConfig.jumpEndModeColor
 | 
					      JUMP_END    -> AceConfig.jumpEndModeColor
 | 
				
			||||||
      DEFINE   -> AceConfig.definitionModeColor
 | 
					      DECLARATION -> AceConfig.definitionModeColor
 | 
				
			||||||
      TARGET   -> AceConfig.targetModeColor
 | 
					      TARGET      -> AceConfig.targetModeColor
 | 
				
			||||||
      DISABLED -> AbstractColorsScheme.INHERITED_COLOR_MARKER
 | 
					      DISABLED    -> AbstractColorsScheme.INHERITED_COLOR_MARKER
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  override fun toString() = when (this) {
 | 
					  override fun toString() = when (this) {
 | 
				
			||||||
@@ -63,6 +75,6 @@ enum class JumpMode {
 | 
				
			|||||||
    JUMP     -> "Jump"
 | 
					    JUMP     -> "Jump"
 | 
				
			||||||
    JUMP_END -> "Jump to End"
 | 
					    JUMP_END -> "Jump to End"
 | 
				
			||||||
    TARGET   -> "Target"
 | 
					    TARGET   -> "Target"
 | 
				
			||||||
    DEFINE   -> "Definition"
 | 
					    DECLARATION   -> "Definition"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,51 +3,54 @@ package org.acejump.input
 | 
				
			|||||||
import org.acejump.config.AceConfig
 | 
					import org.acejump.config.AceConfig
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Remembers the current [JumpMode] for a session. Allows cycling [JumpMode]s according to the order defined in configuration, or toggling
 | 
					 * Remembers the current [JumpMode] for a session. Allows cycling
 | 
				
			||||||
 * one specific [JumpMode] on or off.
 | 
					 * [JumpMode]s according to the order defined in configuration, or
 | 
				
			||||||
 | 
					 * toggling one specific [JumpMode] on or off.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal class JumpModeTracker {
 | 
					internal class JumpModeTracker {
 | 
				
			||||||
  private var currentMode = JumpMode.DISABLED
 | 
					  private var currentMode = JumpMode.DISABLED
 | 
				
			||||||
  private var currentIndex = 0
 | 
					  private var currentIndex = 0
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Switches to the next/previous [JumpMode] defined in configuration, skipping any [JumpMode]s that are not assigned. If at least two
 | 
					   * Switches to the next/previous [JumpMode] defined in configuration,
 | 
				
			||||||
   * [JumpMode]s are assigned in the cycle order, then cycling will wrap around. If only one [JumpMode] is assigned, then cycling will
 | 
					   * skipping any [JumpMode]s that are not assigned. If at least two
 | 
				
			||||||
 | 
					   * [JumpMode]s are assigned in the cycle order, then cycling will
 | 
				
			||||||
 | 
					   * wrap around. If only one [JumpMode] is assigned, then cycling will
 | 
				
			||||||
   * toggle that one mode.
 | 
					   * toggle that one mode.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun cycle(forward: Boolean): JumpMode {
 | 
					  fun cycle(forward: Boolean): JumpMode {
 | 
				
			||||||
    val cycleModes = AceConfig.cycleModes
 | 
					    val cycleModes = AceConfig.cycleModes
 | 
				
			||||||
    val direction = if (forward) 1 else -1
 | 
					    val direction = if (forward) 1 else -1
 | 
				
			||||||
    val start = if (currentIndex == 0 && !forward) 0 else currentIndex - 1
 | 
					    val start = if (currentIndex == 0 && !forward) 0 else currentIndex - 1
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    for (offset in 1 until cycleModes.size) {
 | 
					    for (offset in 1 until cycleModes.size) {
 | 
				
			||||||
      val index = (start + cycleModes.size + (offset * direction)) % cycleModes.size
 | 
					      val index = (start + cycleModes.size + (offset * direction)) % cycleModes.size
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      if (cycleModes[index] != JumpMode.DISABLED) {
 | 
					      if (cycleModes[index] != JumpMode.DISABLED) {
 | 
				
			||||||
        currentMode = cycleModes[index]
 | 
					        currentMode = cycleModes[index]
 | 
				
			||||||
        currentIndex = index + 1
 | 
					        currentIndex = index + 1
 | 
				
			||||||
        return currentMode
 | 
					        return currentMode
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    currentMode = JumpMode.DISABLED
 | 
					    currentMode = JumpMode.DISABLED
 | 
				
			||||||
    currentIndex = 0
 | 
					    currentIndex = 0
 | 
				
			||||||
    return currentMode
 | 
					    return currentMode
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Switches to the specified [JumpMode]. If the current mode already equals the specified one, it resets to [JumpMode.DISABLED].
 | 
					   * Switches to the specified [JumpMode]. If the current mode already
 | 
				
			||||||
 | 
					   * equals the specified one, it resets to [JumpMode.DISABLED].
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun toggle(newMode: JumpMode): JumpMode {
 | 
					  fun toggle(newMode: JumpMode): JumpMode {
 | 
				
			||||||
    if (currentMode == newMode) {
 | 
					    if (currentMode == newMode) {
 | 
				
			||||||
      currentMode = JumpMode.DISABLED
 | 
					      currentMode = JumpMode.DISABLED
 | 
				
			||||||
      currentIndex = 0
 | 
					      currentIndex = 0
 | 
				
			||||||
    }
 | 
					    } else {
 | 
				
			||||||
    else {
 | 
					 | 
				
			||||||
      currentMode = newMode
 | 
					      currentMode = newMode
 | 
				
			||||||
      currentIndex = AceConfig.cycleModes.indexOfFirst { it == newMode } + 1
 | 
					      currentIndex = AceConfig.cycleModes.indexOfFirst { it == newMode } + 1
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    return currentMode
 | 
					    return currentMode
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,14 @@
 | 
				
			|||||||
package org.acejump.input
 | 
					package org.acejump.input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import it.unimi.dsi.fastutil.objects.Object2IntMap
 | 
				
			||||||
 | 
					import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
 | 
				
			||||||
 | 
					import java.awt.geom.Point2D
 | 
				
			||||||
 | 
					import kotlin.math.floor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Defines common keyboard layouts. Each layout has a key priority order, based on each key's distance from the home row and how
 | 
					 * Defines common keyboard layouts. Each layout has a key priority order,
 | 
				
			||||||
 * ergonomically difficult they are to press.
 | 
					 * based on each key's distance from the home row and how ergonomically
 | 
				
			||||||
 | 
					 * difficult they are to press.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@Suppress("unused")
 | 
					@Suppress("unused")
 | 
				
			||||||
enum class KeyLayout(internal val rows: Array<String>, priority: String) {
 | 
					enum class KeyLayout(internal val rows: Array<String>, priority: String) {
 | 
				
			||||||
@@ -18,7 +24,38 @@ enum class KeyLayout(internal val rows: Array<String>, priority: String) {
 | 
				
			|||||||
  internal val allChars = rows.joinToString("").toCharArray().apply(CharArray::sort).joinToString("")
 | 
					  internal val allChars = rows.joinToString("").toCharArray().apply(CharArray::sort).joinToString("")
 | 
				
			||||||
  internal val allPriorities = priority.mapIndexed { index, char -> char to index }.toMap()
 | 
					  internal val allPriorities = priority.mapIndexed { index, char -> char to index }.toMap()
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  private val keyDistances: Map<Char, Object2IntMap<Char>> by lazy {
 | 
				
			||||||
 | 
					    val keyDistanceMap = mutableMapOf<Char, Object2IntMap<Char>>()
 | 
				
			||||||
 | 
					    val keyLocations = mutableMapOf<Char, Point2D>()
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    for ((rowIndex, rowChars) in rows.withIndex()) {
 | 
				
			||||||
 | 
					      val keyY = rowIndex * 1.2F // Slightly increase cost of traveling between rows.
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      for ((columnIndex, char) in rowChars.withIndex()) {
 | 
				
			||||||
 | 
					        val keyX = columnIndex + (0.25F * rowIndex) // Assume a 1/4-key uniform stagger.
 | 
				
			||||||
 | 
					        keyLocations[char] = Point2D.Float(keyX, keyY)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    for (fromChar in allChars) {
 | 
				
			||||||
 | 
					      val distances = Object2IntOpenHashMap<Char>()
 | 
				
			||||||
 | 
					      val fromLocation = keyLocations.getValue(fromChar)
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      for (toChar in allChars) {
 | 
				
			||||||
 | 
					        distances[toChar] = floor(2F * fromLocation.distanceSq(keyLocations.getValue(toChar))).toInt()
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      keyDistanceMap[fromChar] = distances
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    keyDistanceMap
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  internal inline fun priority(crossinline tagToChar: (String) -> Char): (String) -> Int? {
 | 
					  internal inline fun priority(crossinline tagToChar: (String) -> Char): (String) -> Int? {
 | 
				
			||||||
    return { allPriorities[tagToChar(it)] }
 | 
					    return { allPriorities[tagToChar(it)] }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  internal fun distanceBetweenKeys(char1: Char, char2: Char): Int {
 | 
				
			||||||
 | 
					    return keyDistances.getValue(char1).getValue(char2)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,48 +7,6 @@ import org.acejump.config.AceSettings
 | 
				
			|||||||
 * with repeated keys (ex. FF, JJ) or adjacent keys (ex. GH, UJ).
 | 
					 * with repeated keys (ex. FF, JJ) or adjacent keys (ex. GH, UJ).
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal object KeyLayoutCache {
 | 
					internal object KeyLayoutCache {
 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
   * Stores keys ordered by proximity to other keys for the QWERTY layout.
 | 
					 | 
				
			||||||
   * TODO: Support more layouts, perhaps generate automatically.
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
  private val qwertyCharacterDistances = mapOf(
 | 
					 | 
				
			||||||
    'j' to "jikmnhuolbgypvftcdrxsezawq8796054321",
 | 
					 | 
				
			||||||
    'f' to "ftgvcdryhbxseujnzawqikmolp5463728190",
 | 
					 | 
				
			||||||
    'k' to "kolmjipnhubgyvftcdrxsezawq9807654321",
 | 
					 | 
				
			||||||
    'd' to "drfcxsetgvzawyhbqujnikmolp4352617890",
 | 
					 | 
				
			||||||
    'l' to "lkopmjinhubgyvftcdrxsezawq0987654321",
 | 
					 | 
				
			||||||
    's' to "sedxzawrfcqtgvyhbujnikmolp3241567890",
 | 
					 | 
				
			||||||
    'a' to "aqwszedxrfctgvyhbujnikmolp1234567890",
 | 
					 | 
				
			||||||
    'h' to "hujnbgyikmvftolcdrpxsezawq6758493021",
 | 
					 | 
				
			||||||
    'g' to "gyhbvftujncdrikmxseolzawpq5647382910",
 | 
					 | 
				
			||||||
    'y' to "yuhgtijnbvfrokmcdeplxswzaq6758493021",
 | 
					 | 
				
			||||||
    't' to "tygfruhbvcdeijnxswokmzaqpl5647382910",
 | 
					 | 
				
			||||||
    'u' to "uijhyokmnbgtplvfrcdexswzaq7869504321",
 | 
					 | 
				
			||||||
    'r' to "rtfdeygvcxswuhbzaqijnokmpl4536271890",
 | 
					 | 
				
			||||||
    'n' to "nbhjmvgyuiklocftpxdrzseawq7685940321",
 | 
					 | 
				
			||||||
    'v' to "vcfgbxdrtyhnzseujmawikqolp5463728190",
 | 
					 | 
				
			||||||
    'm' to "mnjkbhuilvgyopcftxdrzseawq8970654321",
 | 
					 | 
				
			||||||
    'c' to "cxdfvzsertgbawyhnqujmikolp4352617890",
 | 
					 | 
				
			||||||
    'b' to "bvghncftyujmxdrikzseolawqp6574839201",
 | 
					 | 
				
			||||||
    'i' to "iokjuplmnhybgtvfrcdexswzaq8970654321",
 | 
					 | 
				
			||||||
    'e' to "erdswtfcxzaqygvuhbijnokmpl3425167890",
 | 
					 | 
				
			||||||
    'x' to "xzsdcawerfvqtgbyhnujmikolp3241567890",
 | 
					 | 
				
			||||||
    'z' to "zasxqwedcrfvtgbyhnujmikolp1234567890",
 | 
					 | 
				
			||||||
    'o' to "oplkimjunhybgtvfrcdexswzaq9087654321",
 | 
					 | 
				
			||||||
    'w' to "wesaqrdxztfcygvuhbijnokmpl2314567890",
 | 
					 | 
				
			||||||
    'p' to "plokimjunhybgtvfrcdexswzaq0987654321",
 | 
					 | 
				
			||||||
    'q' to "qwaeszrdxtfcygvuhbijnokmpl1234567890",
 | 
					 | 
				
			||||||
    '1' to "1234567890qawzsexdrcftvgybhunjimkolp",
 | 
					 | 
				
			||||||
    '2' to "2134567890qwasezxdrcftvgybhunjimkolp",
 | 
					 | 
				
			||||||
    '3' to "3241567890weqasdrzxcftvgybhunjimkolp",
 | 
					 | 
				
			||||||
    '4' to "4352617890erwsdftqazxcvgybhunjimkolp",
 | 
					 | 
				
			||||||
    '5' to "5463728190rtedfgywsxcvbhuqaznjimkolp",
 | 
					 | 
				
			||||||
    '6' to "6574839201tyrfghuedcvbnjiwsxmkoqazlp",
 | 
					 | 
				
			||||||
    '7' to "7685940321yutghjirfvbnmkoedclpwsxqaz",
 | 
					 | 
				
			||||||
    '8' to "8796054321uiyhjkotgbnmlprfvedcwsxqaz",
 | 
					 | 
				
			||||||
    '9' to "9807654321ioujklpyhnmtgbrfvedcwsxqaz",
 | 
					 | 
				
			||||||
    '0' to "0987654321opiklujmyhntgbrfvedcwsxqaz").mapValues { (_, v) -> v.mapIndexed { index, char -> char to index }.toMap() }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Sorts tags according to current keyboard layout settings, and some predefined rules that force tags with digits, and tags with two
 | 
					   * Sorts tags according to current keyboard layout settings, and some predefined rules that force tags with digits, and tags with two
 | 
				
			||||||
   * keys far apart, to be sorted after other (easier to type) tags.
 | 
					   * keys far apart, to be sorted after other (easier to type) tags.
 | 
				
			||||||
@@ -65,19 +23,16 @@ internal object KeyLayoutCache {
 | 
				
			|||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Called before any lazily initialized properties are used, to ensure that they are initialized even if the settings are missing.
 | 
					   * Called before any lazily initialized properties are used, to ensure that they are initialized even if the settings are missing.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun ensureInitialized(settings: AceSettings) {
 | 
					  fun ensureInitialized(settings: AceSettings) =
 | 
				
			||||||
    if (!::tagOrder.isInitialized) {
 | 
					    if (!::tagOrder.isInitialized) reset(settings) else Unit
 | 
				
			||||||
      reset(settings)
 | 
					
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Re-initializes cached data according to updated settings.
 | 
					   * Re-initializes cached data according to updated settings.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun reset(settings: AceSettings) {
 | 
					  fun reset(settings: AceSettings) {
 | 
				
			||||||
    tagOrder = compareBy(
 | 
					    tagOrder = compareBy(
 | 
				
			||||||
      { it[0].isDigit() || it[1].isDigit() },
 | 
					      { it[0].isDigit() || it[1].isDigit() },
 | 
				
			||||||
      { qwertyCharacterDistances.getValue(it[0]).getValue(it[1]) },
 | 
					      { settings.layout.distanceBetweenKeys(it[0], it[1]) },
 | 
				
			||||||
      settings.layout.priority { it[0] }
 | 
					      settings.layout.priority { it[0] }
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@@ -88,6 +43,8 @@ internal object KeyLayoutCache {
 | 
				
			|||||||
      .joinToString("")
 | 
					      .joinToString("")
 | 
				
			||||||
      .ifEmpty(settings.layout::allChars)
 | 
					      .ifEmpty(settings.layout::allChars)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    allPossibleTags = allPossibleChars.flatMap { a -> allPossibleChars.map { b -> "$a$b".intern() } }.sortedWith(tagOrder)
 | 
					    allPossibleTags = allPossibleChars.flatMap { a ->
 | 
				
			||||||
 | 
					      allPossibleChars.map { b -> "$a$b".intern() }
 | 
				
			||||||
 | 
					    }.sortedWith(tagOrder)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,116 +8,154 @@ import org.acejump.isWordPart
 | 
				
			|||||||
import org.acejump.matchesAt
 | 
					import org.acejump.matchesAt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Searches editor text for matches of a [SearchQuery], and updates previous results when the user [type]s a character.
 | 
					 * Searches editor text for matches of a [SearchQuery], and updates
 | 
				
			||||||
 | 
					 * previous results when the user [type]s a character.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal class SearchProcessor private constructor(private val editor: Editor, query: SearchQuery, boundaries: Boundaries) {
 | 
					internal class SearchProcessor private constructor(
 | 
				
			||||||
 | 
					  private val editors: List<Editor>,
 | 
				
			||||||
 | 
					  query: SearchQuery,
 | 
				
			||||||
 | 
					  results: MutableMap<Editor, IntArrayList>
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
  companion object {
 | 
					  companion object {
 | 
				
			||||||
    fun fromChar(editor: Editor, char: Char, boundaries: Boundaries): SearchProcessor {
 | 
					    fun fromChar(editors: List<Editor>, char: Char, boundaries: Boundaries) =
 | 
				
			||||||
      return SearchProcessor(editor, SearchQuery.Literal(char.toString()), boundaries)
 | 
					      SearchProcessor(editors, SearchQuery.Literal(char.toString()), boundaries)
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
    
 | 
					    fun fromRegex(editors: List<Editor>, pattern: String, boundaries: Boundaries) =
 | 
				
			||||||
    fun fromRegex(editor: Editor, pattern: String, boundaries: Boundaries): SearchProcessor {
 | 
					      SearchProcessor(editors, SearchQuery.RegularExpression(pattern), boundaries)
 | 
				
			||||||
      return SearchProcessor(editor, SearchQuery.RegularExpression(pattern), boundaries)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  var query = query
 | 
					  private constructor(editors: List<Editor>, query: SearchQuery, boundaries: Boundaries) : this(editors, query, mutableMapOf()) {
 | 
				
			||||||
    private set
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  var results = IntArrayList(0)
 | 
					 | 
				
			||||||
    private set
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  init {
 | 
					 | 
				
			||||||
    val regex = query.toRegex()
 | 
					    val regex = query.toRegex()
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    if (regex != null) {
 | 
					    if (regex != null) {
 | 
				
			||||||
      val offsetRange = boundaries.getOffsetRange(editor)
 | 
					      for (editor in editors) {
 | 
				
			||||||
      var result = regex.find(editor.immutableText, offsetRange.first)
 | 
					        val offsets = IntArrayList()
 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      while (result != null) {
 | 
					 | 
				
			||||||
        val index = result.range.first // For some reason regex matches can be out of bounds, but boundary check prevents an exception.
 | 
					 | 
				
			||||||
        val highlightEnd = index + query.getHighlightLength("", index)
 | 
					 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        if (highlightEnd > offsetRange.last) {
 | 
					        val offsetRange = boundaries.getOffsetRange(editor)
 | 
				
			||||||
          break
 | 
					        var result = regex.find(editor.immutableText, offsetRange.first)
 | 
				
			||||||
        }
 | 
					        
 | 
				
			||||||
        else if (boundaries.isOffsetInside(editor, index)) {
 | 
					        while (result != null) {
 | 
				
			||||||
          results.add(index)
 | 
					          // For some reason regex matches can be out of bounds, but
 | 
				
			||||||
 | 
					          // boundary check prevents an exception.
 | 
				
			||||||
 | 
					          val index = result.range.first
 | 
				
			||||||
 | 
					          val highlightEnd = index + query.getHighlightLength("", index)
 | 
				
			||||||
 | 
					          
 | 
				
			||||||
 | 
					          if (highlightEnd > offsetRange.last) {
 | 
				
			||||||
 | 
					            break
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          else if (boundaries.isOffsetInside(editor, index)) {
 | 
				
			||||||
 | 
					            offsets.add(index)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          
 | 
				
			||||||
 | 
					          result = result.next()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        result = result.next()
 | 
					        results[editor] = offsets
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  var query: SearchQuery = query
 | 
				
			||||||
 | 
					    private set
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  var results: MutableMap<Editor, IntArrayList> = results
 | 
				
			||||||
 | 
					    private set
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Appends a character to the search query and removes all search results that no longer match the query. If the last typed character
 | 
					   * Appends a character to the search query and removes all search results
 | 
				
			||||||
   * transitioned the search query from a non-word to a word, it notifies the [Tagger] to reassign all tags. If the new query does not
 | 
					   * that no longer match the query. If the last typed character transitioned
 | 
				
			||||||
   * make sense because it would remove every result, the change is reverted and this function returns false.
 | 
					   * the search query from a non-word to a word, it notifies the [Tagger] to
 | 
				
			||||||
 | 
					   * reassign all tags. If the new query is invalid because it would remove
 | 
				
			||||||
 | 
					   * every result, the change is reverted and this function returns false.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun type(char: Char, tagger: Tagger): Boolean {
 | 
					  fun type(char: Char, tagger: Tagger): Boolean {
 | 
				
			||||||
    val newQuery = query.rawText + char
 | 
					    val newQuery = query.rawText + char
 | 
				
			||||||
    val chars = editor.immutableText
 | 
					 | 
				
			||||||
    val canMatchTag = tagger.canQueryMatchAnyTag(newQuery)
 | 
					    val canMatchTag = tagger.canQueryMatchAnyTag(newQuery)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // If the typed character is not compatible with any existing tag or as a continuation of any previous occurrence, reject the query
 | 
					    // If the typed character is not compatible with any existing tag or as
 | 
				
			||||||
    // change and return false to indicate that nothing else should happen.
 | 
					    // a continuation of any previous occurrence, reject the query change
 | 
				
			||||||
 | 
					    // and return false to indicate that nothing else should happen.
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    if (newQuery.length > 1 && !canMatchTag && results.none { chars.matchesAt(it, newQuery, ignoreCase = true) }) {
 | 
					    if (newQuery.length > 1 && !canMatchTag && !isContinuation(newQuery)) {
 | 
				
			||||||
      return false
 | 
					      return false
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					  
 | 
				
			||||||
    // If the typed character transitioned the search query from a non-word to a word, and the typed character does not belong to an
 | 
					    // If the typed character transitioned the search query from a non-word
 | 
				
			||||||
    // existing tag, we basically restart the search at the beginning of every new word, and unmark existing results so that all tags get
 | 
					    // to a word, and the typed character does not belong to an existing tag,
 | 
				
			||||||
    // regenerated immediately afterwards. Although this causes tags to change, it is one solution for conflicts between tag characters and
 | 
					    // we basically restart the search at the beginning of every new word,
 | 
				
			||||||
    // search query characters, and moving searches across word boundaries during search should be fairly uncommon.
 | 
					    // and unmark existing results so that all tags get regenerated immediately
 | 
				
			||||||
    
 | 
					    // afterwards. Although this causes tags to change, it is one solution for
 | 
				
			||||||
 | 
					    // conflicts between tag characters and search query characters, and moving
 | 
				
			||||||
 | 
					    // searches across word boundaries during search should be fairly uncommon.
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
    if (!canMatchTag && newQuery.length >= 2 && !newQuery[newQuery.length - 2].isWordPart && char.isWordPart) {
 | 
					    if (!canMatchTag && newQuery.length >= 2 && !newQuery[newQuery.length - 2].isWordPart && char.isWordPart) {
 | 
				
			||||||
      query = SearchQuery.Literal(char.toString())
 | 
					      query = SearchQuery.Literal(char.toString())
 | 
				
			||||||
      tagger.unmark()
 | 
					      tagger.unmark()
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      val iter = results.iterator()
 | 
					      for ((editor, offsets) in results) {
 | 
				
			||||||
      while (iter.hasNext()) {
 | 
					        val chars = editor.immutableText
 | 
				
			||||||
        val movedOffset = iter.nextInt() + newQuery.length - 1
 | 
					        val iter = offsets.iterator()
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        if (movedOffset < chars.length && chars[movedOffset].equals(char, ignoreCase = true)) {
 | 
					        while (iter.hasNext()) {
 | 
				
			||||||
          iter.set(movedOffset)
 | 
					          val movedOffset = iter.nextInt() + newQuery.length - 1
 | 
				
			||||||
        }
 | 
					          
 | 
				
			||||||
        else {
 | 
					          if (movedOffset < chars.length && chars[movedOffset].equals(char, ignoreCase = true)) {
 | 
				
			||||||
          iter.remove()
 | 
					            iter.set(movedOffset)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          else {
 | 
				
			||||||
 | 
					            iter.remove()
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    } else {
 | 
				
			||||||
    else {
 | 
					 | 
				
			||||||
      removeObsoleteResults(newQuery, tagger)
 | 
					      removeObsoleteResults(newQuery, tagger)
 | 
				
			||||||
      query = SearchQuery.Literal(newQuery)
 | 
					      query = SearchQuery.Literal(newQuery)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    return true
 | 
					    return true
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * After updating the query, removes all results that no longer match the search query.
 | 
					   * Returns true if the new query is a continuation of any remaining search query.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  private fun isContinuation(newQuery: String): Boolean {
 | 
				
			||||||
 | 
					    for ((editor, offsets) in results) {
 | 
				
			||||||
 | 
					      val chars = editor.immutableText
 | 
				
			||||||
 | 
					      if (offsets.any { chars.matchesAt(it, newQuery, ignoreCase = true) }) {
 | 
				
			||||||
 | 
					        return true
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    return false
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * After updating the query, removes all results that no longer match
 | 
				
			||||||
 | 
					   * the search query.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  private fun removeObsoleteResults(newQuery: String, tagger: Tagger) {
 | 
					  private fun removeObsoleteResults(newQuery: String, tagger: Tagger) {
 | 
				
			||||||
    val lastCharOffset = newQuery.lastIndex
 | 
					    val lastCharOffset = newQuery.lastIndex
 | 
				
			||||||
    val lastChar = newQuery[lastCharOffset]
 | 
					    val lastChar = newQuery[lastCharOffset]
 | 
				
			||||||
    val ignoreCase = newQuery[0].isLowerCase()
 | 
					    val ignoreCase = newQuery[0].isLowerCase()
 | 
				
			||||||
    val chars = editor.immutableText
 | 
					  
 | 
				
			||||||
 | 
					    for ((editor, offsets) in results.entries.toList()) {
 | 
				
			||||||
 | 
					      val chars = editor.immutableText
 | 
				
			||||||
 | 
					      val remaining = IntArrayList()
 | 
				
			||||||
 | 
					      val iter = offsets.iterator()
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    val remaining = IntArrayList()
 | 
					      while (iter.hasNext()) {
 | 
				
			||||||
    val iter = results.iterator()
 | 
					        val offset = iter.nextInt()
 | 
				
			||||||
    
 | 
					        val endOffset = offset + lastCharOffset
 | 
				
			||||||
    while (iter.hasNext()) {
 | 
					        val lastTypedCharMatches = endOffset < chars.length &&
 | 
				
			||||||
      val offset = iter.nextInt()
 | 
					          chars[endOffset].equals(lastChar, ignoreCase)
 | 
				
			||||||
      val endOffset = offset + lastCharOffset
 | 
					 | 
				
			||||||
      val lastTypedCharMatches = endOffset < chars.length && chars[endOffset].equals(lastChar, ignoreCase)
 | 
					 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      if (lastTypedCharMatches || tagger.isQueryCompatibleWithTagAt(newQuery, offset)) {
 | 
					        if (lastTypedCharMatches ||
 | 
				
			||||||
        remaining.add(offset)
 | 
					          tagger.isQueryCompatibleWithTagAt(newQuery, Tag(editor, offset))) {
 | 
				
			||||||
 | 
					          remaining.add(offset)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    results = remaining
 | 
					      results[editor] = remaining
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,56 +7,53 @@ import org.acejump.countMatchingCharacters
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
internal sealed class SearchQuery {
 | 
					internal sealed class SearchQuery {
 | 
				
			||||||
  abstract val rawText: String
 | 
					  abstract val rawText: String
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Returns how many characters the search occurrence highlight should cover.
 | 
					   * Returns how many characters the search occurrence highlight should cover.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  abstract fun getHighlightLength(text: CharSequence, offset: Int): Int
 | 
					  abstract fun getHighlightLength(text: CharSequence, offset: Int): Int
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Converts the query into a regular expression to find the initial matches.
 | 
					   * Converts the query into a regular expression to find the initial matches.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  abstract fun toRegex(): Regex?
 | 
					  abstract fun toRegex(): Regex?
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Searches for all occurrences of a literal text query. If the first character of the query is lowercase, then the entire query will be
 | 
					   * Searches for all occurrences of a literal text query. If the first
 | 
				
			||||||
 | 
					   * character of the query is lowercase, then the entire query will be
 | 
				
			||||||
   * case-insensitive.
 | 
					   * case-insensitive.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * Each occurrence must either match the entire query, or match the query up to a point so that the rest of the query matches the
 | 
					   * Each occurrence must either match the entire query, or match the query
 | 
				
			||||||
   * beginning of a tag at the location of the occurrence.
 | 
					   * up to a point so that the rest of the query matches the  beginning of
 | 
				
			||||||
 | 
					   * a tag at the location of the occurrence.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  class Literal(override var rawText: String) : SearchQuery() {
 | 
					  class Literal(override var rawText: String): SearchQuery() {
 | 
				
			||||||
    init {
 | 
					    init {
 | 
				
			||||||
      require(rawText.isNotEmpty())
 | 
					      require(rawText.isNotEmpty())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    override fun getHighlightLength(text: CharSequence, offset: Int): Int {
 | 
					    override fun getHighlightLength(text: CharSequence, offset: Int): Int =
 | 
				
			||||||
      return text.countMatchingCharacters(offset, rawText)
 | 
					      text.countMatchingCharacters(offset, rawText)
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    override fun toRegex(): Regex {
 | 
					    override fun toRegex(): Regex {
 | 
				
			||||||
      val options = mutableSetOf(RegexOption.MULTILINE)
 | 
					      val options = mutableSetOf(RegexOption.MULTILINE)
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      if (rawText.first().isLowerCase()) {
 | 
					      if (rawText.first().isLowerCase())
 | 
				
			||||||
        options.add(RegexOption.IGNORE_CASE)
 | 
					        options.add(RegexOption.IGNORE_CASE)
 | 
				
			||||||
      }
 | 
					
 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      return Regex(Regex.escape(rawText), options)
 | 
					      return Regex(Regex.escape(rawText), options)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Searches for all matches of a regular expression.
 | 
					   * Searches for all matches of a regular expression.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  class RegularExpression(private var pattern: String) : SearchQuery() {
 | 
					  class RegularExpression(private var pattern: String): SearchQuery() {
 | 
				
			||||||
    override val rawText = ""
 | 
					    override val rawText = ""
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
    override fun getHighlightLength(text: CharSequence, offset: Int): Int {
 | 
					    override fun getHighlightLength(text: CharSequence, offset: Int) = 1
 | 
				
			||||||
      return 1
 | 
					
 | 
				
			||||||
    }
 | 
					    override fun toRegex(): Regex =
 | 
				
			||||||
    
 | 
					      Regex(pattern, setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE))
 | 
				
			||||||
    override fun toRegex(): Regex {
 | 
					 | 
				
			||||||
      return Regex(pattern, setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE))
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +1,16 @@
 | 
				
			|||||||
package org.acejump.search
 | 
					package org.acejump.search
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
import it.unimi.dsi.fastutil.ints.*
 | 
					import it.unimi.dsi.fastutil.ints.IntList
 | 
				
			||||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
 | 
					import it.unimi.dsi.fastutil.ints.IntOpenHashSet
 | 
				
			||||||
import org.acejump.boundaries.EditorOffsetCache
 | 
					import org.acejump.boundaries.EditorOffsetCache
 | 
				
			||||||
import org.acejump.boundaries.StandardBoundaries
 | 
					import org.acejump.boundaries.StandardBoundaries.VISIBLE_ON_SCREEN
 | 
				
			||||||
import org.acejump.config.AceConfig
 | 
					import org.acejump.config.AceConfig
 | 
				
			||||||
import org.acejump.immutableText
 | 
					import org.acejump.immutableText
 | 
				
			||||||
import org.acejump.input.KeyLayoutCache
 | 
					import org.acejump.input.KeyLayoutCache
 | 
				
			||||||
import org.acejump.isWordPart
 | 
					import org.acejump.isWordPart
 | 
				
			||||||
import org.acejump.wordEndPlus
 | 
					import org.acejump.wordEndPlus
 | 
				
			||||||
import java.util.*
 | 
					import java.util.*
 | 
				
			||||||
import kotlin.collections.HashMap
 | 
					 | 
				
			||||||
import kotlin.collections.HashSet
 | 
					 | 
				
			||||||
import kotlin.math.max
 | 
					import kotlin.math.max
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -53,140 +51,147 @@ import kotlin.math.max
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal class Solver private constructor(
 | 
					internal class Solver private constructor(
 | 
				
			||||||
  private val editor: Editor,
 | 
					  private val editorPriority: List<Editor>,
 | 
				
			||||||
  private val queryLength: Int,
 | 
					  private val queryLength: Int,
 | 
				
			||||||
  private val newResults: IntList,
 | 
					  private val newResults: Map<Editor, IntList>,
 | 
				
			||||||
  private val allResults: IntList
 | 
					  private val allResults: Map<Editor, IntList>
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  companion object {
 | 
					  companion object {
 | 
				
			||||||
    fun solve(
 | 
					    fun solve(
 | 
				
			||||||
      editor: Editor, query: SearchQuery, newResults: IntList, allResults: IntList, tags: List<String>, cache: EditorOffsetCache
 | 
					      editorPriority: List<Editor>,
 | 
				
			||||||
    ): Map<String, Int> {
 | 
					      query: SearchQuery,
 | 
				
			||||||
      return Solver(editor, max(1, query.rawText.length), newResults, allResults).map(tags, cache)
 | 
					      newResults: Map<Editor, IntList>,
 | 
				
			||||||
    }
 | 
					      allResults: Map<Editor, IntList>,
 | 
				
			||||||
 | 
					      tags: List<String>,
 | 
				
			||||||
 | 
					      caches: Map<Editor, EditorOffsetCache>
 | 
				
			||||||
 | 
					    ): Map<String, Tag> =
 | 
				
			||||||
 | 
					      Solver(editorPriority, max(1, query.rawText.length), newResults, allResults)
 | 
				
			||||||
 | 
					        .map(tags, caches)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private var newTags = Object2IntOpenHashMap<String>(KeyLayoutCache.allPossibleTags.size)
 | 
					  private var newTags = HashMap<String, Tag>(KeyLayoutCache.allPossibleTags.size)
 | 
				
			||||||
  private val newTagIndices = IntOpenHashSet()
 | 
					  private val newTagIndices = newResults.keys.associateWith { IntOpenHashSet() }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private var allWordFragments = HashSet<String>(allResults.size).apply {
 | 
					  private var allWordFragments =
 | 
				
			||||||
    val iter = allResults.iterator()
 | 
					    HashSet<String>(allResults.values.sumOf(IntList::size)).apply {
 | 
				
			||||||
    while (iter.hasNext()) {
 | 
					      for ((editor, offsets) in allResults) {
 | 
				
			||||||
      forEachWordFragment(iter.nextInt()) { add(it) }
 | 
					        val iter = offsets.iterator()
 | 
				
			||||||
 | 
					        while (iter.hasNext()) forEachWordFragment(editor, iter.nextInt()) { add(it) }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					
 | 
				
			||||||
  
 | 
					  fun map(availableTags: List<String>, caches: Map<Editor, EditorOffsetCache>): Map<String, Tag> {
 | 
				
			||||||
  fun map(availableTags: List<String>, cache: EditorOffsetCache): Map<String, Int> {
 | 
					    val eligibleSitesByTag = HashMap<String, MutableList<Tag>>(100)
 | 
				
			||||||
    val eligibleSitesByTag = HashMap<String, IntList>(100)
 | 
					 | 
				
			||||||
    val tagsByFirstLetter = availableTags.groupBy { it[0] }
 | 
					    val tagsByFirstLetter = availableTags.groupBy { it[0] }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    val iter = newResults.iterator()
 | 
					    for ((editor, offsets) in newResults) {
 | 
				
			||||||
    while (iter.hasNext()) {
 | 
					      val iter = offsets.iterator()
 | 
				
			||||||
      val site = iter.nextInt()
 | 
					      while (iter.hasNext()) {
 | 
				
			||||||
      
 | 
					        val site = iter.nextInt()
 | 
				
			||||||
      for ((firstLetter, tags) in tagsByFirstLetter.entries) {
 | 
					        
 | 
				
			||||||
        if (canTagBeginWithChar(site, firstLetter)) {
 | 
					        for ((firstLetter, tags) in tagsByFirstLetter.entries) {
 | 
				
			||||||
          for (tag in tags) {
 | 
					          if (canTagBeginWithChar(editor, site, firstLetter)) {
 | 
				
			||||||
            eligibleSitesByTag.getOrPut(tag) { IntArrayList(10) }.add(site)
 | 
					            for (tag in tags) {
 | 
				
			||||||
 | 
					              eligibleSitesByTag.getOrPut(tag, ::mutableListOf).add(Tag(editor, site))
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    val matchingSites = HashMap<IntList, IntArray>()
 | 
					    val matchingSites = HashMap<MutableList<Tag>, MutableList<Tag>>()
 | 
				
			||||||
    val matchingSitesAsArrays = IdentityHashMap<String, IntArray>() // Keys are guaranteed to be from a single collection.
 | 
					    // Keys are guaranteed to be from a single collection.
 | 
				
			||||||
 | 
					    val matchingSitesAsArrays = IdentityHashMap<String, MutableList<Tag>>()
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    val siteOrder = siteOrder(cache)
 | 
					    val siteOrder = siteOrder(caches)
 | 
				
			||||||
    val tagOrder = KeyLayoutCache.tagOrder
 | 
					    val tagOrder = KeyLayoutCache.tagOrder
 | 
				
			||||||
      .thenComparingInt { eligibleSitesByTag.getValue(it).size }
 | 
					      .thenComparingInt { eligibleSitesByTag.getValue(it).size }
 | 
				
			||||||
      .thenBy(AceConfig.layout.priority(String::last))
 | 
					      .thenBy(AceConfig.layout.priority(String::last))
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    val sortedTags = eligibleSitesByTag.keys.toMutableList().apply {
 | 
					    val sortedTags = eligibleSitesByTag.keys.toMutableList().apply {
 | 
				
			||||||
      sortWith(tagOrder)
 | 
					      sortWith(tagOrder)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    for ((key, value) in eligibleSitesByTag.entries) {
 | 
					    for ((mark, tags) in eligibleSitesByTag.entries) {
 | 
				
			||||||
      matchingSitesAsArrays[key] = matchingSites.getOrPut(value) {
 | 
					      matchingSitesAsArrays[mark] = matchingSites.getOrPut(tags) {
 | 
				
			||||||
        value.toIntArray().apply { IntArrays.mergeSort(this, siteOrder) }
 | 
					        tags.toMutableList().apply { sortWith(siteOrder) }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    var totalAssigned = 0
 | 
					    var totalAssigned = 0
 | 
				
			||||||
 | 
					    val totalResults = newResults.values.sumOf(IntList::size)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    for (tag in sortedTags) {
 | 
					    for (tag in sortedTags) {
 | 
				
			||||||
      if (totalAssigned == newResults.size) {
 | 
					      if (totalAssigned == totalResults) {
 | 
				
			||||||
        break
 | 
					        break
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      if (tryToAssignTag(tag, matchingSitesAsArrays.getValue(tag))) {
 | 
					      if (tryToAssignTag(tag, matchingSitesAsArrays.getValue(tag))) {
 | 
				
			||||||
        totalAssigned++
 | 
					        totalAssigned++
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    return newTags
 | 
					    return newTags
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private fun tryToAssignTag(tag: String, sites: IntArray): Boolean {
 | 
					  private fun tryToAssignTag(mark: String, tags: List<Tag>): Boolean {
 | 
				
			||||||
    if (newTags.containsKey(tag)) {
 | 
					    if (newTags.containsKey(mark)) return false
 | 
				
			||||||
      return false
 | 
					
 | 
				
			||||||
    }
 | 
					    val tag = tags.firstOrNull { it.offset !in newTagIndices.getValue(it.editor) } ?: return false
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    val index = sites.firstOrNull { it !in newTagIndices } ?: return false
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    @Suppress("ReplacePutWithAssignment")
 | 
					    @Suppress("ReplacePutWithAssignment")
 | 
				
			||||||
    newTags.put(tag, index)
 | 
					    newTags.put(mark, tag)
 | 
				
			||||||
    newTagIndices.add(index)
 | 
					    newTagIndices.getValue(tag.editor).add(tag.offset)
 | 
				
			||||||
    return true
 | 
					    return true
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private fun siteOrder(caches: Map<Editor, EditorOffsetCache>) = Comparator<Tag> { a, b ->
 | 
				
			||||||
 | 
					    val aEditor = a.editor
 | 
				
			||||||
 | 
					    val bEditor = b.editor
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  private fun siteOrder(cache: EditorOffsetCache) = IntComparator { a, b ->
 | 
					    if (aEditor !== bEditor) {
 | 
				
			||||||
    val aIsVisible = StandardBoundaries.VISIBLE_ON_SCREEN.isOffsetInside(editor, a, cache)
 | 
					      val aEditorIndex = editorPriority.indexOf(aEditor)
 | 
				
			||||||
    val bIsVisible = StandardBoundaries.VISIBLE_ON_SCREEN.isOffsetInside(editor, b, cache)
 | 
					      val bEditorIndex = editorPriority.indexOf(bEditor)
 | 
				
			||||||
    
 | 
					      // For multiple editors, prioritize them based on the provided order.
 | 
				
			||||||
 | 
					      return@Comparator if (aEditorIndex < bEditorIndex) -1 else 1
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					    val aIsVisible = VISIBLE_ON_SCREEN.isOffsetInside(aEditor, a.offset, caches.getValue(aEditor))
 | 
				
			||||||
 | 
					    val bIsVisible = VISIBLE_ON_SCREEN.isOffsetInside(bEditor, b.offset, caches.getValue(bEditor))
 | 
				
			||||||
    if (aIsVisible != bIsVisible) {
 | 
					    if (aIsVisible != bIsVisible) {
 | 
				
			||||||
      // Sites in immediate view should come first.
 | 
					      // Sites in immediate view should come first.
 | 
				
			||||||
      return@IntComparator if (aIsVisible) -1 else 1
 | 
					      return@Comparator if (aIsVisible) -1 else 1
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					  
 | 
				
			||||||
    val chars = editor.immutableText
 | 
					    val aIsNotWordStart = aEditor.immutableText[max(0, a.offset - 1)].isWordPart
 | 
				
			||||||
    val aIsNotWordStart = chars[max(0, a - 1)].isWordPart
 | 
					    val bIsNotWordStart = bEditor.immutableText[max(0, b.offset - 1)].isWordPart
 | 
				
			||||||
    val bIsNotWordStart = chars[max(0, b - 1)].isWordPart
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    if (aIsNotWordStart != bIsNotWordStart) {
 | 
					    if (aIsNotWordStart != bIsNotWordStart) {
 | 
				
			||||||
      // Ensure that the first letter of a word is prioritized for tagging.
 | 
					      // Ensure that the first letter of a word is prioritized for tagging.
 | 
				
			||||||
      return@IntComparator if (bIsNotWordStart) -1 else 1
 | 
					      return@Comparator if (bIsNotWordStart) -1 else 1
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					  
 | 
				
			||||||
    when {
 | 
					    when {
 | 
				
			||||||
      a < b -> -1
 | 
					      a.offset < b.offset -> -1
 | 
				
			||||||
      a > b -> 1
 | 
					      a.offset > b.offset -> 1
 | 
				
			||||||
      else  -> 0
 | 
					      else                -> 0
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private fun canTagBeginWithChar(site: Int, char: Char): Boolean {
 | 
					  private fun canTagBeginWithChar(editor: Editor, site: Int, char: Char): Boolean {
 | 
				
			||||||
    if (char.toString() in allWordFragments) {
 | 
					    if (char.toString() in allWordFragments) return false
 | 
				
			||||||
      return false
 | 
					
 | 
				
			||||||
    }
 | 
					    forEachWordFragment(editor, site) { if (it + char in allWordFragments) return false }
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    forEachWordFragment(site) {
 | 
					 | 
				
			||||||
      if (it + char in allWordFragments) {
 | 
					 | 
				
			||||||
        return false
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    return true
 | 
					    return true
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private inline fun forEachWordFragment(site: Int, callback: (String) -> Unit) {
 | 
					  private inline fun forEachWordFragment(editor: Editor, site: Int, callback: (String) -> Unit) {
 | 
				
			||||||
    val chars = editor.immutableText
 | 
					    val chars = editor.immutableText
 | 
				
			||||||
    val left = max(0, site + queryLength - 1)
 | 
					    val left = max(0, site + queryLength - 1)
 | 
				
			||||||
    val right = chars.wordEndPlus(site)
 | 
					    val right = chars.wordEndPlus(site)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    val builder = StringBuilder(1 + right - left)
 | 
					    val builder = StringBuilder(1 + right - left)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    for (i in left..right) {
 | 
					    for (i in left..right) {
 | 
				
			||||||
      builder.append(chars[i].toLowerCase())
 | 
					      builder.append(chars[i].lowercase())
 | 
				
			||||||
      callback(builder.toString())
 | 
					      callback(builder.toString())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								src/main/kotlin/org/acejump/search/Tag.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/main/kotlin/org/acejump/search/Tag.kt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					package org.acejump.search
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					data class Tag(val editor: Editor, val offset: Int)
 | 
				
			||||||
@@ -1,135 +1,158 @@
 | 
				
			|||||||
package org.acejump.search
 | 
					package org.acejump.search
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.common.collect.ArrayListMultimap
 | 
				
			||||||
import com.google.common.collect.HashBiMap
 | 
					import com.google.common.collect.HashBiMap
 | 
				
			||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
import it.unimi.dsi.fastutil.ints.IntArrayList
 | 
					import it.unimi.dsi.fastutil.ints.IntArrayList
 | 
				
			||||||
import it.unimi.dsi.fastutil.ints.IntList
 | 
					import it.unimi.dsi.fastutil.ints.IntList
 | 
				
			||||||
import org.acejump.ExternalUsage
 | 
					import org.acejump.ExternalUsage
 | 
				
			||||||
import org.acejump.boundaries.EditorOffsetCache
 | 
					import org.acejump.boundaries.EditorOffsetCache
 | 
				
			||||||
import org.acejump.boundaries.StandardBoundaries
 | 
					import org.acejump.boundaries.StandardBoundaries.VISIBLE_ON_SCREEN
 | 
				
			||||||
import org.acejump.immutableText
 | 
					import org.acejump.immutableText
 | 
				
			||||||
import org.acejump.input.KeyLayoutCache.allPossibleTags
 | 
					import org.acejump.input.KeyLayoutCache.allPossibleTags
 | 
				
			||||||
import org.acejump.isWordPart
 | 
					import org.acejump.isWordPart
 | 
				
			||||||
import org.acejump.matchesAt
 | 
					import org.acejump.matchesAt
 | 
				
			||||||
import org.acejump.view.Tag
 | 
					import org.acejump.view.TagMarker
 | 
				
			||||||
import java.util.AbstractMap.SimpleImmutableEntry
 | 
					import java.util.AbstractMap.SimpleImmutableEntry
 | 
				
			||||||
import kotlin.collections.component1
 | 
					import kotlin.collections.component1
 | 
				
			||||||
import kotlin.collections.component2
 | 
					import kotlin.collections.component2
 | 
				
			||||||
 | 
					import kotlin.math.min
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Assigns tags to search occurrences, updates them when the search query changes, and requests a jump if the search query matches a tag.
 | 
					 * Assigns tags to search occurrences, updates them when the search query changes, and requests a jump if the search query matches a tag.
 | 
				
			||||||
 | 
					 * The ordering of [editors] may be used to prioritize tagging editors earlier in the list in case of conflicts.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal class Tagger(private val editor: Editor) {
 | 
					internal class Tagger(private val editors: List<Editor>) {
 | 
				
			||||||
  private var tagMap = HashBiMap.create<String, Int>()
 | 
					  private var tagMap = HashBiMap.create<String, Tag>()
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  val hasTags
 | 
					  val hasTags
 | 
				
			||||||
    get() = tagMap.isNotEmpty()
 | 
					    get() = tagMap.isNotEmpty()
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  @ExternalUsage
 | 
					  @ExternalUsage
 | 
				
			||||||
  val tags
 | 
					  val tags
 | 
				
			||||||
    get() = tagMap.map { SimpleImmutableEntry(it.key, it.value) }.sortedBy { it.value }
 | 
					    get() = tagMap.map { SimpleImmutableEntry(it.key, it.value) }.sortedBy { it.value.offset }
 | 
				
			||||||
    
 | 
					  
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Removes all markers, allowing them to be regenerated from scratch.
 | 
					   * Removes all markers, allowing them to be regenerated from scratch.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun unmark() {
 | 
					  fun unmark() {
 | 
				
			||||||
    tagMap = HashBiMap.create()
 | 
					    tagMap = HashBiMap.create()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Assigns tags to as many results as possible, keeping previously assigned tags. Returns a [TaggingResult.Jump] if the current search
 | 
					   * Assigns tags to as many results as possible, keeping previously assigned
 | 
				
			||||||
   * query matches any existing tag and we should jump to it and end the session, or [TaggingResult.Mark] to continue the session with
 | 
					   * tags. Returns a [TaggingResult.Jump] if the current search query matches
 | 
				
			||||||
   * updated tag markers.
 | 
					   * any existing tag and we should jump to it and end the session, or
 | 
				
			||||||
 | 
					   * [TaggingResult.Mark] to continue the session with updated tag markers.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * Note that the [results] collection will be mutated.
 | 
					   * Note that the [results] collection will be mutated.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun markOrJump(query: SearchQuery, results: IntList): TaggingResult {
 | 
					  fun markOrJump(query: SearchQuery, results: Map<Editor, IntList>): TaggingResult {
 | 
				
			||||||
    val isRegex = query is SearchQuery.RegularExpression
 | 
					    val isRegex = query is SearchQuery.RegularExpression
 | 
				
			||||||
    val queryText = if (isRegex) " ${query.rawText}" else query.rawText[0] + query.rawText.drop(1).toLowerCase()
 | 
					    val queryText = if (isRegex) " ${query.rawText}" else query.rawText[0] + query.rawText.drop(1).lowercase()
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    val availableTags = allPossibleTags.filter { !queryText.endsWith(it[0]) && it !in tagMap }
 | 
					    val availableTags = allPossibleTags.filter { !queryText.endsWith(it[0]) && it !in tagMap }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (!isRegex) {
 | 
					    if (!isRegex) {
 | 
				
			||||||
      for (entry in tagMap.entries) {
 | 
					      for (entry in tagMap.entries) {
 | 
				
			||||||
        if (entry solves queryText) {
 | 
					        if (entry solves queryText) {
 | 
				
			||||||
          return TaggingResult.Jump(entry.value)
 | 
					          return TaggingResult.Jump(query = queryText.substringBefore(entry.key), mark = entry.key, tag = entry.value)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      if (queryText.length == 1) {
 | 
					      if (queryText.length == 1) {
 | 
				
			||||||
        removeResultsWithOverlappingTags(results)
 | 
					        for ((editor, offsets) in results) {
 | 
				
			||||||
      }
 | 
					          removeResultsWithOverlappingTags(editor, offsets)
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    if (!isRegex || tagMap.isEmpty()) {
 | 
					 | 
				
			||||||
      tagMap = assignTagsAndMerge(results, availableTags, query, queryText)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    return TaggingResult.Mark(createTagMarkers(results, query.rawText.ifEmpty { null }))
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
   * Assigns as many unassigned tags as possible, and merges them with the existing compatible tags.
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
  private fun assignTagsAndMerge(results: IntList, availableTags: List<String>, query: SearchQuery, queryText: String): HashBiMap<String, Int> {
 | 
					 | 
				
			||||||
    val cache = EditorOffsetCache.new()
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    results.sort { a, b ->
 | 
					 | 
				
			||||||
      val aIsVisible = StandardBoundaries.VISIBLE_ON_SCREEN.isOffsetInside(editor, a, cache)
 | 
					 | 
				
			||||||
      val bIsVisible = StandardBoundaries.VISIBLE_ON_SCREEN.isOffsetInside(editor, b, cache)
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      when {
 | 
					 | 
				
			||||||
        aIsVisible && !bIsVisible -> -1
 | 
					 | 
				
			||||||
        bIsVisible && !aIsVisible -> 1
 | 
					 | 
				
			||||||
        else                      -> 0
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    val allAssignedTags = mutableMapOf<String, Int>()
 | 
					 | 
				
			||||||
    val oldCompatibleTags = tagMap.filter { isTagCompatibleWithQuery(it.key, it.value, queryText) || it.value in results }
 | 
					 | 
				
			||||||
    val vacantResults: IntList
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    if (oldCompatibleTags.isEmpty()) {
 | 
					 | 
				
			||||||
      vacantResults = results
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else {
 | 
					 | 
				
			||||||
      vacantResults = IntArrayList()
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      val iter = results.iterator()
 | 
					 | 
				
			||||||
      while (iter.hasNext()) {
 | 
					 | 
				
			||||||
        val offset = iter.nextInt()
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
        if (offset !in oldCompatibleTags.values) {
 | 
					 | 
				
			||||||
          vacantResults.add(offset)
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!isRegex || tagMap.isEmpty())
 | 
				
			||||||
 | 
					      tagMap = assignTagsAndMerge(results, availableTags, query, queryText)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val resultTags = results.flatMap { (editor, offsets) -> offsets.map { Tag(editor, it) } }
 | 
				
			||||||
 | 
					    return TaggingResult.Mark(createTagMarkers(resultTags, query.rawText.ifEmpty { null }))
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Assigns as many unassigned tags as possible, and merges them with
 | 
				
			||||||
 | 
					   * the existing compatible tags.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  private fun assignTagsAndMerge(
 | 
				
			||||||
 | 
					    results: Map<Editor, IntList>,
 | 
				
			||||||
 | 
					    availableTags: List<String>,
 | 
				
			||||||
 | 
					    query: SearchQuery,
 | 
				
			||||||
 | 
					    queryText: String
 | 
				
			||||||
 | 
					  ): HashBiMap<String, Tag> {
 | 
				
			||||||
 | 
					    val caches = results.keys.associateWith { EditorOffsetCache.new() }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for ((editor, offsets) in results) {
 | 
				
			||||||
 | 
					      val cache = caches.getValue(editor)
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      offsets.sort { a, b ->
 | 
				
			||||||
 | 
					        val aIsVisible = VISIBLE_ON_SCREEN.isOffsetInside(editor, a, cache)
 | 
				
			||||||
 | 
					        val bIsVisible = VISIBLE_ON_SCREEN.isOffsetInside(editor, b, cache)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      when {
 | 
				
			||||||
 | 
					        aIsVisible && !bIsVisible -> -1
 | 
				
			||||||
 | 
					        bIsVisible && !aIsVisible -> 1
 | 
				
			||||||
 | 
					        else -> 0}
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val allAssignedTags = mutableMapOf<String, Tag>()
 | 
				
			||||||
 | 
					    val oldCompatibleTags = tagMap.filter { (mark, tag) ->
 | 
				
			||||||
 | 
					      isTagCompatibleWithQuery(mark, tag, queryText) || results[tag.editor]?.contains(tag.offset) == true
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    val vacantResults: Map<Editor, IntList>
 | 
				
			||||||
 | 
					    if (oldCompatibleTags.isEmpty()) {
 | 
				
			||||||
 | 
					      vacantResults = results
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      val vacant = mutableMapOf<Editor, IntList>()
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      for ((editor, offsets) in results) {
 | 
				
			||||||
 | 
					        val list = IntArrayList()
 | 
				
			||||||
 | 
					        val iter = offsets.iterator()
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        while (iter.hasNext()) {
 | 
				
			||||||
 | 
					          val tag = Tag(editor, iter.nextInt())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (tag !in oldCompatibleTags.values) {
 | 
				
			||||||
 | 
					            list.add(tag.offset)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        vacant[editor] = list
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      vacantResults = vacant
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    allAssignedTags.putAll(oldCompatibleTags)
 | 
					    allAssignedTags.putAll(oldCompatibleTags)
 | 
				
			||||||
    allAssignedTags.putAll(Solver.solve(editor, query, vacantResults, results, availableTags, cache))
 | 
					    allAssignedTags.putAll(Solver.solve(editors, query, vacantResults, results, availableTags, caches))
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    return allAssignedTags.mapKeysTo(HashBiMap.create(allAssignedTags.size)) { (tag, _) ->
 | 
					    return allAssignedTags.mapKeysTo(HashBiMap.create(allAssignedTags.size)) { (tag, _) ->
 | 
				
			||||||
      // Avoid matching query - will trigger a jump.
 | 
					      // Avoid matching query - will trigger a jump.
 | 
				
			||||||
      // TODO: lift this constraint.
 | 
					      // TODO: lift this constraint.
 | 
				
			||||||
      val queryEndsWith = queryText.endsWith(tag[0]) || queryText.endsWith(tag)
 | 
					      val queryEndsWith = queryText.endsWith(tag[0]) || queryText.endsWith(tag)
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      if (!queryEndsWith && canShortenTag(tag, allAssignedTags))
 | 
					      if (!queryEndsWith && canShortenTag(tag, allAssignedTags.keys))
 | 
				
			||||||
        tag[0].toString()
 | 
					        tag[0].toString()
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
        tag
 | 
					        tag
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  private infix fun Map.Entry<String, Int>.solves(query: String): Boolean {
 | 
					  private infix fun Map.Entry<String, Tag>.solves(query: String): Boolean {
 | 
				
			||||||
    return query.endsWith(key, true) && isTagCompatibleWithQuery(key, value, query)
 | 
					    return query.endsWith(key, true) && isTagCompatibleWithQuery(key, value, query)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  private fun isTagCompatibleWithQuery(tag: String, offset: Int, query: String): Boolean {
 | 
					  private fun isTagCompatibleWithQuery(marker: String, tag: Tag, query: String): Boolean {
 | 
				
			||||||
    return editor.immutableText.matchesAt(offset, getPlaintextPortion(query, tag), ignoreCase = true)
 | 
					    return tag.editor.immutableText.matchesAt(tag.offset, getPlaintextPortion(query, marker), ignoreCase = true)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  fun isQueryCompatibleWithTagAt(query: String, offset: Int): Boolean {
 | 
					  fun isQueryCompatibleWithTagAt(query: String, tag: Tag): Boolean {
 | 
				
			||||||
    return tagMap.inverse()[offset].let { it != null && isTagCompatibleWithQuery(it, offset, query) }
 | 
					    return tagMap.inverse()[tag].let { it != null && isTagCompatibleWithQuery(it, tag, query) }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  fun canQueryMatchAnyTag(query: String): Boolean {
 | 
					  fun canQueryMatchAnyTag(query: String): Boolean {
 | 
				
			||||||
@@ -138,9 +161,9 @@ internal class Tagger(private val editor: Editor) {
 | 
				
			|||||||
      tagPortion.isNotEmpty() && tag.startsWith(tagPortion, ignoreCase = true) && isTagCompatibleWithQuery(tag, offset, query)
 | 
					      tagPortion.isNotEmpty() && tag.startsWith(tagPortion, ignoreCase = true) && isTagCompatibleWithQuery(tag, offset, query)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private fun removeResultsWithOverlappingTags(results: IntList) {
 | 
					  private fun removeResultsWithOverlappingTags(editor: Editor, offsets: IntList) {
 | 
				
			||||||
    val iter = results.iterator()
 | 
					    val iter = offsets.iterator()
 | 
				
			||||||
    val chars = editor.immutableText
 | 
					    val chars = editor.immutableText
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    while (iter.hasNext()) {
 | 
					    while (iter.hasNext()) {
 | 
				
			||||||
@@ -150,48 +173,55 @@ internal class Tagger(private val editor: Editor) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  private fun createTagMarkers(results: IntList, literalQueryText: String?): List<Tag> {
 | 
					  private fun createTagMarkers(tags: Collection<Tag>, literalQueryText: String?): MutableMap<Editor, Collection<TagMarker>> {
 | 
				
			||||||
    val tagMapInv = tagMap.inverse()
 | 
					    val tagMapInv = tagMap.inverse()
 | 
				
			||||||
    return results.mapNotNull { index -> tagMapInv[index]?.let { tag -> Tag.create(editor, tag, index, literalQueryText) } }
 | 
					    val markers = ArrayListMultimap.create<Editor, TagMarker>(editors.size, min(tags.size, 50))
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    for (tag in tags) {
 | 
				
			||||||
 | 
					      val mark = tagMapInv[tag] ?: continue
 | 
				
			||||||
 | 
					      val editor = tag.editor
 | 
				
			||||||
 | 
					      val marker = TagMarker.create(editor, mark, tag.offset, literalQueryText)
 | 
				
			||||||
 | 
					      markers.put(editor, marker)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    return markers.asMap()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  private companion object {
 | 
					  private companion object {
 | 
				
			||||||
    private fun CharSequence.canTagWithoutOverlap(loc: Int) = when {
 | 
					    private fun CharSequence.canTagWithoutOverlap(loc: Int) = when {
 | 
				
			||||||
      loc - 1 < 0                                                                             -> true
 | 
					      loc - 1 < 0 -> true
 | 
				
			||||||
      loc + 1 >= length                                                                       -> true
 | 
					      loc + 1 >= length -> true
 | 
				
			||||||
      this[loc] isUnlike this[loc - 1]                                                        -> true
 | 
					      this[loc] isUnlike this[loc - 1] -> true
 | 
				
			||||||
      this[loc] isUnlike this[loc + 1]                                                        -> true
 | 
					      this[loc] isUnlike this[loc + 1] -> true
 | 
				
			||||||
      this[loc] != this[loc - 1]                                                              -> true
 | 
					      this[loc] != this[loc - 1] -> true
 | 
				
			||||||
      this[loc] != this[loc + 1]                                                              -> true
 | 
					      this[loc] != this[loc + 1] -> true
 | 
				
			||||||
      this[loc + 1] == '\r' || this[loc + 1] == '\n'                                          -> true
 | 
					      this[loc + 1] == '\r' || this[loc + 1] == '\n' -> true
 | 
				
			||||||
      this[loc - 1] == this[loc] && this[loc] == this[loc + 1]                                -> false
 | 
					      this[loc - 1] == this[loc] && this[loc] == this[loc + 1] -> false
 | 
				
			||||||
      this[loc + 1].isWhitespace() && this[(loc + 2).coerceAtMost(length - 1)].isWhitespace() -> true
 | 
					      this[loc + 1].isWhitespace() && this[(loc + 2).coerceAtMost(length - 1)].isWhitespace() -> true
 | 
				
			||||||
      else                                                                                    -> false
 | 
					      else -> false
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    private infix fun Char.isUnlike(other: Char): Boolean {
 | 
					    private infix fun Char.isUnlike(other: Char) =
 | 
				
			||||||
      return this.isWordPart xor other.isWordPart || this.isWhitespace() xor other.isWhitespace()
 | 
					      this.isWordPart xor other.isWordPart ||
 | 
				
			||||||
 | 
					        this.isWhitespace() xor other.isWhitespace()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private fun getPlaintextPortion(query: String, marker: String) = when {
 | 
				
			||||||
 | 
					      query.endsWith(marker, true) -> query.dropLast(marker.length)
 | 
				
			||||||
 | 
					      query.endsWith(marker.first(), true) -> query.dropLast(1)
 | 
				
			||||||
 | 
					      else -> query
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    private fun getPlaintextPortion(query: String, tag: String) = when {
 | 
					    private fun getTagPortion(query: String, marker: String) = when {
 | 
				
			||||||
      query.endsWith(tag, true)         -> query.dropLast(tag.length)
 | 
					      query.endsWith(marker, true) -> query.takeLast(marker.length)
 | 
				
			||||||
      query.endsWith(tag.first(), true) -> query.dropLast(1)
 | 
					      query.endsWith(marker.first(), true) -> query.takeLast(1)
 | 
				
			||||||
      else                              -> query
 | 
					      else -> ""
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
    private fun getTagPortion(query: String, tag: String) = when {
 | 
					    private fun canShortenTag(marker: String, markers: Collection<String>): Boolean {
 | 
				
			||||||
      query.endsWith(tag, true)         -> query.takeLast(tag.length)
 | 
					      for (other in markers)
 | 
				
			||||||
      query.endsWith(tag.first(), true) -> query.takeLast(1)
 | 
					        if (marker != other && marker[0] == other[0])
 | 
				
			||||||
      else                              -> ""
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    private fun canShortenTag(tag: String, tagMap: Map<String, Int>): Boolean {
 | 
					 | 
				
			||||||
      for (other in tagMap.keys) {
 | 
					 | 
				
			||||||
        if (tag != other && tag[0] == other[0]) {
 | 
					 | 
				
			||||||
          return false
 | 
					          return false
 | 
				
			||||||
        }
 | 
					
 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      return true
 | 
					      return true
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,9 @@
 | 
				
			|||||||
package org.acejump.search
 | 
					package org.acejump.search
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.acejump.view.Tag
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
 | 
					import org.acejump.view.TagMarker
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal sealed class TaggingResult {
 | 
					sealed class TaggingResult {
 | 
				
			||||||
  class Jump(val offset: Int) : TaggingResult()
 | 
					  class Jump(val query: String, val mark: String, val tag: Tag): TaggingResult()
 | 
				
			||||||
  class Mark(val tags: List<Tag>) : TaggingResult()
 | 
					  class Mark(val markers: MutableMap<Editor, Collection<TagMarker>>): TaggingResult()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								src/main/kotlin/org/acejump/session/AceJumpListener.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/main/kotlin/org/acejump/session/AceJumpListener.kt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					package org.acejump.session
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					interface AceJumpListener {
 | 
				
			||||||
 | 
					  fun finished(mark: String?, query: String?)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -3,33 +3,38 @@ package org.acejump.session
 | 
				
			|||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Holds [Editor] caret settings. The settings are saved the moment a [Session] starts, modified to indicate AceJump states, and restored
 | 
					 * Holds [Editor] caret settings. The settings are saved the
 | 
				
			||||||
 * once the [Session] ends.
 | 
					 * moment a [Session] starts, modified to indicate AceJump
 | 
				
			||||||
 | 
					 * states, and restored once the [Session] ends.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal data class EditorSettings(private val isBlockCursor: Boolean, private val isBlinkCaret: Boolean, private val isReadOnly: Boolean) {
 | 
					internal data class EditorSettings(
 | 
				
			||||||
 | 
					  private val isBlockCursor: Boolean,
 | 
				
			||||||
 | 
					  private val isBlinkCaret: Boolean,
 | 
				
			||||||
 | 
					  private val isReadOnly: Boolean
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
  companion object {
 | 
					  companion object {
 | 
				
			||||||
    fun setup(editor: Editor): EditorSettings {
 | 
					    fun setup(editor: Editor): EditorSettings {
 | 
				
			||||||
      val settings = editor.settings
 | 
					      val settings = editor.settings
 | 
				
			||||||
      val document = editor.document
 | 
					      val document = editor.document
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      val original = EditorSettings(
 | 
					      val original = EditorSettings(
 | 
				
			||||||
        isBlockCursor = settings.isBlockCursor,
 | 
					        isBlockCursor = settings.isBlockCursor,
 | 
				
			||||||
        isBlinkCaret = settings.isBlinkCaret,
 | 
					        isBlinkCaret = settings.isBlinkCaret,
 | 
				
			||||||
        isReadOnly = !document.isWritable
 | 
					        isReadOnly = !document.isWritable
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      settings.isBlockCursor = true
 | 
					      settings.isBlockCursor = true
 | 
				
			||||||
      settings.isBlinkCaret = false
 | 
					      settings.isBlinkCaret = false
 | 
				
			||||||
      document.setReadOnly(true)
 | 
					      document.setReadOnly(true)
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      return original
 | 
					      return original
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun restore(editor: Editor) {
 | 
					  fun restore(editor: Editor) {
 | 
				
			||||||
    val settings = editor.settings
 | 
					    val settings = editor.settings
 | 
				
			||||||
    val document = editor.document
 | 
					    val document = editor.document
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    settings.isBlockCursor = isBlockCursor
 | 
					    settings.isBlockCursor = isBlockCursor
 | 
				
			||||||
    settings.isBlinkCaret = isBlinkCaret
 | 
					    settings.isBlinkCaret = isBlinkCaret
 | 
				
			||||||
    document.setReadOnly(isReadOnly)
 | 
					    document.setReadOnly(isReadOnly)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,13 +4,17 @@ import com.intellij.openapi.actionSystem.DataContext
 | 
				
			|||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
import com.intellij.openapi.editor.ScrollType
 | 
					import com.intellij.openapi.editor.ScrollType
 | 
				
			||||||
import com.intellij.openapi.editor.actionSystem.TypedActionHandler
 | 
					import com.intellij.openapi.editor.actionSystem.TypedActionHandler
 | 
				
			||||||
import com.intellij.openapi.editor.colors.EditorColors
 | 
					import com.intellij.openapi.editor.colors.EditorColors.CARET_COLOR
 | 
				
			||||||
import org.acejump.ExternalUsage
 | 
					import com.intellij.util.containers.ContainerUtil
 | 
				
			||||||
 | 
					import it.unimi.dsi.fastutil.ints.IntArrayList
 | 
				
			||||||
 | 
					import org.acejump.*
 | 
				
			||||||
 | 
					import org.acejump.action.TagScroller
 | 
				
			||||||
import org.acejump.action.TagJumper
 | 
					import org.acejump.action.TagJumper
 | 
				
			||||||
import org.acejump.action.TagVisitor
 | 
					import org.acejump.action.TagVisitor
 | 
				
			||||||
import org.acejump.boundaries.Boundaries
 | 
					import org.acejump.boundaries.Boundaries
 | 
				
			||||||
import org.acejump.boundaries.EditorOffsetCache
 | 
					import org.acejump.boundaries.EditorOffsetCache
 | 
				
			||||||
import org.acejump.boundaries.StandardBoundaries
 | 
					import org.acejump.boundaries.StandardBoundaries.VISIBLE_ON_SCREEN
 | 
				
			||||||
 | 
					import org.acejump.boundaries.StandardBoundaries.WHOLE_FILE
 | 
				
			||||||
import org.acejump.config.AceConfig
 | 
					import org.acejump.config.AceConfig
 | 
				
			||||||
import org.acejump.input.EditorKeyListener
 | 
					import org.acejump.input.EditorKeyListener
 | 
				
			||||||
import org.acejump.input.JumpMode
 | 
					import org.acejump.input.JumpMode
 | 
				
			||||||
@@ -22,191 +26,281 @@ import org.acejump.search.Tagger
 | 
				
			|||||||
import org.acejump.search.TaggingResult
 | 
					import org.acejump.search.TaggingResult
 | 
				
			||||||
import org.acejump.view.TagCanvas
 | 
					import org.acejump.view.TagCanvas
 | 
				
			||||||
import org.acejump.view.TextHighlighter
 | 
					import org.acejump.view.TextHighlighter
 | 
				
			||||||
 | 
					import java.util.*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Manages an AceJump session for a single [Editor].
 | 
					 * Manages an AceJump session for one or more [Editor]s.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class Session(private val editor: Editor) {
 | 
					class Session(private val mainEditor: Editor, private val jumpEditors: List<Editor>) {
 | 
				
			||||||
 | 
					  private val listeners: MutableList<AceJumpListener> =
 | 
				
			||||||
 | 
					    ContainerUtil.createLockFreeCopyOnWriteList()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private var boundaries: Boundaries = defaultBoundaries
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private companion object {
 | 
					  private companion object {
 | 
				
			||||||
    private val defaultBoundaries
 | 
					    private val defaultBoundaries
 | 
				
			||||||
      get() = if (AceConfig.searchWholeFile) StandardBoundaries.WHOLE_FILE else StandardBoundaries.VISIBLE_ON_SCREEN
 | 
					      get() = if (AceConfig.searchWholeFile) WHOLE_FILE else VISIBLE_ON_SCREEN
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private val originalSettings = EditorSettings.setup(editor)
 | 
					  private val originalSettings = EditorSettings.setup(mainEditor)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private val jumpModeTracker = JumpModeTracker()
 | 
					  private val jumpModeTracker = JumpModeTracker()
 | 
				
			||||||
  private var jumpMode = JumpMode.DISABLED
 | 
					  private var jumpMode = JumpMode.DISABLED
 | 
				
			||||||
    set(value) {
 | 
					    set(value) {
 | 
				
			||||||
      field = value
 | 
					      field = value
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      if (value === JumpMode.DISABLED) {
 | 
					      if (value === JumpMode.DISABLED) {
 | 
				
			||||||
        end()
 | 
					        end()
 | 
				
			||||||
      }
 | 
					      } else {
 | 
				
			||||||
      else {
 | 
					 | 
				
			||||||
        searchProcessor?.let { textHighlighter.render(it.results, it.query, jumpMode) }
 | 
					        searchProcessor?.let { textHighlighter.render(it.results, it.query, jumpMode) }
 | 
				
			||||||
        editor.colorsScheme.setColor(EditorColors.CARET_COLOR, value.caretColor)
 | 
					        mainEditor.colorsScheme.setColor(CARET_COLOR, value.caretColor)
 | 
				
			||||||
        editor.contentComponent.repaint()
 | 
					        mainEditor.contentComponent.repaint()
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private var searchProcessor: SearchProcessor? = null
 | 
					  private var searchProcessor: SearchProcessor? = null
 | 
				
			||||||
  private var tagger = Tagger(editor)
 | 
					  private var tagger = Tagger(jumpEditors)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private val tagJumper
 | 
					  private val tagJumper
 | 
				
			||||||
    get() = TagJumper(editor, jumpMode, searchProcessor)
 | 
					    get() = TagJumper(jumpMode, searchProcessor)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private val tagVisitor
 | 
					  private val tagVisitor
 | 
				
			||||||
    get() = searchProcessor?.let { TagVisitor(editor, it, tagJumper) }
 | 
					    get() = searchProcessor?.let { TagVisitor(mainEditor, it, tagJumper) }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private val textHighlighter = TextHighlighter(editor)
 | 
					  private val tagScroller
 | 
				
			||||||
  private val tagCanvas = TagCanvas(editor)
 | 
					    get() = searchProcessor?.let { TagScroller(mainEditor, it) }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
 | 
					  private val textHighlighter = TextHighlighter()
 | 
				
			||||||
 | 
					  private val tagCanvases = jumpEditors.associateWith(::TagCanvas)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @ExternalUsage
 | 
					  @ExternalUsage
 | 
				
			||||||
  val tags
 | 
					  val tags
 | 
				
			||||||
    get() = tagger.tags
 | 
					    get() = tagger.tags
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  init {
 | 
					  init {
 | 
				
			||||||
    KeyLayoutCache.ensureInitialized(AceConfig.settings)
 | 
					    KeyLayoutCache.ensureInitialized(AceConfig.settings)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    EditorKeyListener.attach(editor, object : TypedActionHandler {
 | 
					    EditorKeyListener.attach(mainEditor, object: TypedActionHandler {
 | 
				
			||||||
      override fun execute(editor: Editor, charTyped: Char, context: DataContext) {
 | 
					      override fun execute(editor: Editor, charTyped: Char, context: DataContext) {
 | 
				
			||||||
        var processor = searchProcessor
 | 
					        var processor = searchProcessor
 | 
				
			||||||
        val hadTags = tagger.hasTags
 | 
					        val hadTags = tagger.hasTags
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        if (processor == null) {
 | 
					        if (processor == null) {
 | 
				
			||||||
          processor = SearchProcessor.fromChar(editor, charTyped, defaultBoundaries).also { searchProcessor = it }
 | 
					          processor = SearchProcessor.fromChar(
 | 
				
			||||||
        }
 | 
					            jumpEditors, charTyped, boundaries
 | 
				
			||||||
        else if (!processor.type(charTyped, tagger)) {
 | 
					          ).also { searchProcessor = it }
 | 
				
			||||||
 | 
					        } else if (!processor.type(charTyped, tagger)) {
 | 
				
			||||||
          return
 | 
					          return
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        updateSearch(processor, markImmediately = hadTags, shiftMode = charTyped.isUpperCase())
 | 
					        updateSearch(
 | 
				
			||||||
 | 
					          processor, markImmediately = hadTags,
 | 
				
			||||||
 | 
					          shiftMode = charTyped.isUpperCase()
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Updates text highlights and tag markers according to the current search state. Dispatches jumps if the search query matches a tag.
 | 
					   * Updates text highlights and tag markers according to the current
 | 
				
			||||||
 | 
					   * search state. Dispatches jumps if the search query matches a tag.
 | 
				
			||||||
   * If all tags are outside view, scrolls to the closest one.
 | 
					   * If all tags are outside view, scrolls to the closest one.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  private fun updateSearch(processor: SearchProcessor, markImmediately: Boolean, shiftMode: Boolean = false) {
 | 
					  private fun updateSearch(
 | 
				
			||||||
 | 
					    processor: SearchProcessor,
 | 
				
			||||||
 | 
					    markImmediately: Boolean,
 | 
				
			||||||
 | 
					    shiftMode: Boolean = false
 | 
				
			||||||
 | 
					  ) {
 | 
				
			||||||
    val query = processor.query
 | 
					    val query = processor.query
 | 
				
			||||||
    val results = processor.results
 | 
					    val results = processor.results
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    textHighlighter.render(results, query, jumpMode)
 | 
					    textHighlighter.render(results, query, jumpMode)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (!markImmediately && query.rawText.let { it.length < AceConfig.minQueryLength && it.all(Char::isLetterOrDigit) }) {
 | 
					    if (!markImmediately &&
 | 
				
			||||||
 | 
					      query.rawText.let {
 | 
				
			||||||
 | 
					        it.length < AceConfig.minQueryLength &&
 | 
				
			||||||
 | 
					          it.all(Char::isLetterOrDigit)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
      return
 | 
					      return
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    when (val result = tagger.markOrJump(query, results.clone())) {
 | 
					    when (val result = tagger.markOrJump(query, results.clone())) {
 | 
				
			||||||
      is TaggingResult.Jump -> {
 | 
					      is TaggingResult.Jump -> {
 | 
				
			||||||
        tagJumper.jump(result.offset, shiftMode)
 | 
					        tagJumper.jump(result.tag, shiftMode, isCrossEditor = mainEditor !== result.tag.editor)
 | 
				
			||||||
        tagCanvas.removeMarkers()
 | 
					        tagCanvases.values.forEach(TagCanvas::removeMarkers)
 | 
				
			||||||
        end()
 | 
					        end(result)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      is TaggingResult.Mark -> {
 | 
					      is TaggingResult.Mark -> {
 | 
				
			||||||
        val tags = result.tags
 | 
					        val markers = result.markers
 | 
				
			||||||
        tagCanvas.setMarkers(tags)
 | 
					 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        val cache = EditorOffsetCache.new()
 | 
					        for ((editor, canvas) in tagCanvases) {
 | 
				
			||||||
        val boundaries = StandardBoundaries.VISIBLE_ON_SCREEN
 | 
					          canvas.setMarkers(markers[editor].orEmpty())
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        if (tags.none { boundaries.isOffsetInside(editor, it.offsetL, cache) || boundaries.isOffsetInside(editor, it.offsetR, cache) }) {
 | 
					        if (jumpEditors.all { editor ->
 | 
				
			||||||
 | 
					            val cache = EditorOffsetCache.new()
 | 
				
			||||||
 | 
					            markers[editor].let { it == null || it.none { marker ->
 | 
				
			||||||
 | 
					              VISIBLE_ON_SCREEN.isOffsetInside(editor, marker.offsetL, cache) ||
 | 
				
			||||||
 | 
					              VISIBLE_ON_SCREEN.isOffsetInside(editor, marker.offsetR, cache) } }
 | 
				
			||||||
 | 
					        }) {
 | 
				
			||||||
          tagVisitor?.scrollToClosest()
 | 
					          tagVisitor?.scrollToClosest()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @ExternalUsage
 | 
				
			||||||
 | 
					  fun markResults(resultsToMark: SortedSet<Int>) {
 | 
				
			||||||
 | 
					    val jumpEditor = jumpEditors.singleOrNull() ?: return
 | 
				
			||||||
 | 
					    markResults(mapOf(jumpEditor to resultsToMark))
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  @ExternalUsage
 | 
				
			||||||
 | 
					  fun markResults(resultsToMark: Map<Editor, Collection<Int>>) {
 | 
				
			||||||
 | 
					    tagger = Tagger(jumpEditors)
 | 
				
			||||||
 | 
					    tagCanvases.values.forEach { it.setMarkers(emptyList()) }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					    val processor = SearchProcessor.fromRegex(jumpEditors, "", defaultBoundaries)
 | 
				
			||||||
 | 
					      .apply {
 | 
				
			||||||
 | 
					        results.clear()
 | 
				
			||||||
 | 
					        for ((editor, offsets) in resultsToMark) {
 | 
				
			||||||
 | 
					          if (editor in jumpEditors) {
 | 
				
			||||||
 | 
					            results[editor] = IntArrayList(offsets)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
   * Starts a regular expression search. If a search was already active, it will be reset alongside its tags and highlights.
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
  fun startRegexSearch(pattern: String, boundaries: Boundaries) {
 | 
					 | 
				
			||||||
    tagger = Tagger(editor)
 | 
					 | 
				
			||||||
    tagCanvas.setMarkers(emptyList())
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    val processor = SearchProcessor.fromRegex(editor, pattern, boundaries.intersection(defaultBoundaries)).also { searchProcessor = it }
 | 
					 | 
				
			||||||
    updateSearch(processor, markImmediately = true)
 | 
					    updateSearch(processor, markImmediately = true)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Starts a regular expression search. If a search was already active, it will be reset alongside its tags and highlights.
 | 
					   * Starts a regular expression search. If a search was already active,
 | 
				
			||||||
 | 
					   * it will be reset alongside its tags and highlights.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun startRegexSearch(pattern: Pattern, boundaries: Boundaries) {
 | 
					
 | 
				
			||||||
    startRegexSearch(pattern.regex, boundaries)
 | 
					  @ExternalUsage
 | 
				
			||||||
 | 
					  fun startRegexSearch(pattern: String, boundaries: Boundaries) {
 | 
				
			||||||
 | 
					    tagger = Tagger(jumpEditors)
 | 
				
			||||||
 | 
					    tagCanvases.values.forEach { it.setMarkers(emptyList()) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val processor = SearchProcessor.fromRegex(
 | 
				
			||||||
 | 
					      jumpEditors, pattern,
 | 
				
			||||||
 | 
					      boundaries.intersection(defaultBoundaries)
 | 
				
			||||||
 | 
					    ).also { searchProcessor = it }
 | 
				
			||||||
 | 
					    updateSearch(processor, markImmediately = true)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Starts a regular expression search. If a search was already active,
 | 
				
			||||||
 | 
					   * it will be reset alongside its tags and highlights.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @ExternalUsage
 | 
				
			||||||
 | 
					  fun startRegexSearch(pattern: Pattern, boundaries: Boundaries) =
 | 
				
			||||||
 | 
					    startRegexSearch(pattern.regex, boundaries)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * See [JumpModeTracker.cycle].
 | 
					   * See [JumpModeTracker.cycle].
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun cycleNextJumpMode() {
 | 
					  fun cycleNextJumpMode() {
 | 
				
			||||||
    jumpMode = jumpModeTracker.cycle(forward = true)
 | 
					    jumpMode = jumpModeTracker.cycle(forward = true)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * See [JumpModeTracker.cycle].
 | 
					   * See [JumpModeTracker.cycle].
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun cyclePreviousJumpMode() {
 | 
					  fun cyclePreviousJumpMode() {
 | 
				
			||||||
    jumpMode = jumpModeTracker.cycle(forward = false)
 | 
					    jumpMode = jumpModeTracker.cycle(forward = false)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * See [JumpModeTracker.toggle]
 | 
					   * See [JumpModeTracker.toggle]
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun toggleJumpMode(newMode: JumpMode) {
 | 
					  fun toggleJumpMode(newMode: JumpMode) {
 | 
				
			||||||
    jumpMode = jumpModeTracker.toggle(newMode)
 | 
					    jumpMode = jumpModeTracker.toggle(newMode)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
 | 
					  @ExternalUsage
 | 
				
			||||||
 | 
					  fun toggleJumpMode(newMode: JumpMode, boundaries: Boundaries) {
 | 
				
			||||||
 | 
					    this.boundaries = this.boundaries.intersection(boundaries)
 | 
				
			||||||
 | 
					    jumpMode = jumpModeTracker.toggle(newMode)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * See [TagVisitor.visitPrevious]. If there are no tags, nothing happens.
 | 
					   * See [TagVisitor.visitPrevious]. If there are no tags, nothing happens.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun visitPreviousTag() {
 | 
					  fun visitPreviousTag() =
 | 
				
			||||||
    if (tagVisitor?.visitPrevious() == true) {
 | 
					    if (tagVisitor?.visitPrevious() == true) end() else Unit
 | 
				
			||||||
      end()
 | 
					
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * See [TagVisitor.visitNext]. If there are no tags, nothing happens.
 | 
					   * See [TagVisitor.visitNext]. If there are no tags, nothing happens.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun visitNextTag() {
 | 
					  fun visitNextTag() =
 | 
				
			||||||
    if (tagVisitor?.visitNext() == true) {
 | 
					    if (tagVisitor?.visitNext() == true) end() else Unit
 | 
				
			||||||
      end()
 | 
					
 | 
				
			||||||
    }
 | 
					  /**
 | 
				
			||||||
  }
 | 
					   * See [TagVisitor.visitPrevious]. If there are no tags, nothing happens.
 | 
				
			||||||
  
 | 
					   */
 | 
				
			||||||
 | 
					  fun scrollToNextScreenful() = tagScroller?.scroll(true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * See [TagVisitor.visitNext]. If there are no tags, nothing happens.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  fun scrollToPreviousScreenful() = tagScroller?.scroll(false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Ends this session.
 | 
					   * Ends this session.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun end() {
 | 
					  fun end(taggingResult: TaggingResult? = null) =
 | 
				
			||||||
    SessionManager.end(editor)
 | 
					    SessionManager.end(mainEditor, taggingResult)
 | 
				
			||||||
  }
 | 
					
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Clears any currently active search, tags, and highlights. Does not reset [JumpMode].
 | 
					   * Clears any currently active search, tags, and highlights.
 | 
				
			||||||
 | 
					   * Does not reset [JumpMode].
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun restart() {
 | 
					  fun restart() {
 | 
				
			||||||
    tagger = Tagger(editor)
 | 
					    tagger = Tagger(jumpEditors)
 | 
				
			||||||
    searchProcessor = null
 | 
					    searchProcessor = null
 | 
				
			||||||
    tagCanvas.removeMarkers()
 | 
					    tagCanvases.values.forEach(TagCanvas::removeMarkers)
 | 
				
			||||||
    textHighlighter.reset()
 | 
					    textHighlighter.reset()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Should only be used from [SessionManager] to dispose a successfully ended session.
 | 
					   * Should only be used from [SessionManager] to dispose a
 | 
				
			||||||
 | 
					   * successfully ended session.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  internal fun dispose() {
 | 
					  internal fun dispose(taggingResult: TaggingResult?) {
 | 
				
			||||||
    tagger = Tagger(editor)
 | 
					    tagger = Tagger(jumpEditors)
 | 
				
			||||||
    EditorKeyListener.detach(editor)
 | 
					    EditorKeyListener.detach(mainEditor)
 | 
				
			||||||
    tagCanvas.unbind()
 | 
					    tagCanvases.values.forEach(TagCanvas::unbind)
 | 
				
			||||||
    textHighlighter.reset()
 | 
					    textHighlighter.reset()
 | 
				
			||||||
    
 | 
					    EditorsCache.invalidate()
 | 
				
			||||||
    if (!editor.isDisposed) {
 | 
					
 | 
				
			||||||
      originalSettings.restore(editor)
 | 
					    val jumpResult = taggingResult as? TaggingResult.Jump
 | 
				
			||||||
      editor.colorsScheme.setColor(EditorColors.CARET_COLOR, JumpMode.DISABLED.caretColor)
 | 
					    val mark = jumpResult?.mark
 | 
				
			||||||
      editor.scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE)
 | 
					    val query = jumpResult?.query
 | 
				
			||||||
 | 
					    listeners.forEach { it.finished(mark, query) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!mainEditor.isDisposed) {
 | 
				
			||||||
 | 
					      originalSettings.restore(mainEditor)
 | 
				
			||||||
 | 
					      mainEditor.colorsScheme.setColor(CARET_COLOR, JumpMode.DISABLED.caretColor)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val focusedEditor = jumpResult?.tag?.editor ?: mainEditor
 | 
				
			||||||
 | 
					    if (!focusedEditor.isDisposed) {
 | 
				
			||||||
 | 
					      focusedEditor.scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @ExternalUsage
 | 
				
			||||||
 | 
					  fun addAceJumpListener(listener: AceJumpListener) {
 | 
				
			||||||
 | 
					    listeners += listener
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @ExternalUsage
 | 
				
			||||||
 | 
					  fun removeAceJumpListener(listener: AceJumpListener) {
 | 
				
			||||||
 | 
					    listeners -= listener
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,41 +1,53 @@
 | 
				
			|||||||
package org.acejump.session
 | 
					package org.acejump.session
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
 | 
					import org.acejump.ExternalUsage
 | 
				
			||||||
 | 
					import org.acejump.search.TaggingResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Manages active [Session]s in [Editor]s. There may only be one [Session] per [Editor], but multiple [Session]s across multiple [Editor]s
 | 
					 * Manages active [Session]s in [Editor]s. There may only be
 | 
				
			||||||
 * may be active at once.
 | 
					 * one [Session] per [Editor], but multiple [Session]s across
 | 
				
			||||||
 | 
					 * multiple [Editor]s may be active at once.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * It is possible for an [Editor] to be disposed with an active [Session]. In such case, the reference to both will remain until a new
 | 
					 * It is possible for an [Editor] to be disposed with an active
 | 
				
			||||||
 * [Session] starts, at which point the [SessionManager.cleanup] method will purge disposed [Editor]s.
 | 
					 * [Session]. In such case, the reference to both will remain
 | 
				
			||||||
 | 
					 * until a new [Session] starts, at which point the
 | 
				
			||||||
 | 
					 * [SessionManager.cleanup] method will purge disposed [Editor]s.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@ExternalUsage
 | 
				
			||||||
object SessionManager {
 | 
					object SessionManager {
 | 
				
			||||||
  private val sessions = HashMap<Editor, Session>(4)
 | 
					  private val sessions = HashMap<Editor, Session>(4)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Starts a new [Session], or returns an existing [Session] if the specified [Editor] already has one.
 | 
					   * Starts a new [Session], or returns an existing [Session]
 | 
				
			||||||
 | 
					   * if the specified [Editor] already has one.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun start(editor: Editor): Session {
 | 
					  fun start(editor: Editor): Session = start(editor, listOf(editor))
 | 
				
			||||||
    return sessions.getOrPut(editor) { cleanup(); Session(editor) }
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Starts a new multi-editor [Session], or returns an existing [Session] if the specified main [Editor] already has one.
 | 
				
			||||||
 | 
					   * The [mainEditor] is used for typing the search query and tag.
 | 
				
			||||||
 | 
					   * The [jumpEditors] are all editors that will be searched and tagged. The list is ordered so that editors earlier in the list will be
 | 
				
			||||||
 | 
					   * prioritized for tagging in case of conflicts.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  fun start(mainEditor: Editor, jumpEditors: List<Editor>): Session {
 | 
				
			||||||
 | 
					    return sessions.getOrPut(mainEditor) { cleanup(); Session(mainEditor, jumpEditors) }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Returns the active [Session] in the specified [Editor], or null if the [Editor] has no active session.
 | 
					   * Returns the active [Session] in the specified [Editor],
 | 
				
			||||||
 | 
					   * or null if the [Editor] has no active session.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  operator fun get(editor: Editor): Session? {
 | 
					  operator fun get(editor: Editor): Session? = sessions[editor]
 | 
				
			||||||
    return sessions[editor]
 | 
					
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Ends the active [Session] in the specified [Editor], or does nothing if the [Editor] has no active session.
 | 
					   * Ends the active [Session] in the specified [Editor],
 | 
				
			||||||
 | 
					   * or does nothing if the [Editor] has no active session.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun end(editor: Editor) {
 | 
					  fun end(editor: Editor, taggingResult: TaggingResult?) =
 | 
				
			||||||
    sessions.remove(editor)?.dispose()
 | 
					    sessions.remove(editor)?.dispose(taggingResult) ?: Unit
 | 
				
			||||||
  }
 | 
					
 | 
				
			||||||
  
 | 
					  private fun cleanup() = sessions.keys.filter { it.isDisposed }
 | 
				
			||||||
  private fun cleanup() {
 | 
					    .forEach { disposedEditor -> sessions.remove(disposedEditor)?.dispose(null) }
 | 
				
			||||||
    for (disposedEditor in sessions.keys.filter { it.isDisposed }) {
 | 
					 | 
				
			||||||
      sessions.remove(disposedEditor)?.dispose()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ import com.intellij.openapi.editor.Editor
 | 
				
			|||||||
import com.intellij.openapi.editor.event.CaretEvent
 | 
					import com.intellij.openapi.editor.event.CaretEvent
 | 
				
			||||||
import com.intellij.openapi.editor.event.CaretListener
 | 
					import com.intellij.openapi.editor.event.CaretListener
 | 
				
			||||||
import org.acejump.boundaries.EditorOffsetCache
 | 
					import org.acejump.boundaries.EditorOffsetCache
 | 
				
			||||||
import org.acejump.boundaries.StandardBoundaries
 | 
					import org.acejump.boundaries.StandardBoundaries.VISIBLE_ON_SCREEN
 | 
				
			||||||
import java.awt.Graphics
 | 
					import java.awt.Graphics
 | 
				
			||||||
import java.awt.Graphics2D
 | 
					import java.awt.Graphics2D
 | 
				
			||||||
import java.awt.Rectangle
 | 
					import java.awt.Rectangle
 | 
				
			||||||
@@ -16,76 +16,73 @@ import javax.swing.SwingUtilities
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Holds all active tag markers and renders them on top of the editor.
 | 
					 * Holds all active tag markers and renders them on top of the editor.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal class TagCanvas(private val editor: Editor) : JComponent(), CaretListener {
 | 
					internal class TagCanvas(private val editor: Editor): JComponent(), CaretListener {
 | 
				
			||||||
  private var markers: List<Tag>? = null
 | 
					  private var markers: Collection<TagMarker>? = null
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  init {
 | 
					  init {
 | 
				
			||||||
    val contentComponent = editor.contentComponent
 | 
					    val contentComponent = editor.contentComponent
 | 
				
			||||||
    contentComponent.add(this)
 | 
					    contentComponent.add(this)
 | 
				
			||||||
    setBounds(0, 0, contentComponent.width, contentComponent.height)
 | 
					    setBounds(0, 0, contentComponent.width, contentComponent.height)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (ApplicationInfo.getInstance().build.components.first() < 173) {
 | 
					    if (ApplicationInfo.getInstance().build.components.first() < 173)
 | 
				
			||||||
      SwingUtilities.convertPoint(this, location, editor.component.rootPane).let { setLocation(-it.x, -it.y) }
 | 
					      SwingUtilities.convertPoint(this, location, editor.component.rootPane)
 | 
				
			||||||
    }
 | 
					        .let { setLocation(-it.x, -it.y) }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    editor.caretModel.addCaretListener(this)
 | 
					    editor.caretModel.addCaretListener(this)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun unbind() {
 | 
					  fun unbind() {
 | 
				
			||||||
    markers = null
 | 
					    markers = null
 | 
				
			||||||
    editor.contentComponent.remove(this)
 | 
					    editor.contentComponent.remove(this)
 | 
				
			||||||
    editor.caretModel.removeCaretListener(this)
 | 
					    editor.caretModel.removeCaretListener(this)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Ensures that all tags and the outline around the selected tag are repainted. It should not be necessary to repaint the entire tag
 | 
					   * Ensures that all tags and the outline around the selected tag are
 | 
				
			||||||
 | 
					   * repainted. It should not be necessary to repaint the entire tag
 | 
				
			||||||
   * canvas, but the cost of repainting visible tags is negligible.
 | 
					   * canvas, but the cost of repainting visible tags is negligible.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  override fun caretPositionChanged(event: CaretEvent) {
 | 
					  override fun caretPositionChanged(event: CaretEvent) = repaint()
 | 
				
			||||||
    repaint()
 | 
					
 | 
				
			||||||
  }
 | 
					  fun setMarkers(markers: Collection<TagMarker>) {
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  fun setMarkers(markers: List<Tag>) {
 | 
					 | 
				
			||||||
    this.markers = markers
 | 
					    this.markers = markers
 | 
				
			||||||
    repaint()
 | 
					    repaint()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  fun removeMarkers() {
 | 
					  fun removeMarkers() {
 | 
				
			||||||
    this.markers = emptyList()
 | 
					    markers = emptyList()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  override fun paint(g: Graphics) {
 | 
					  override fun paint(g: Graphics) =
 | 
				
			||||||
    if (!markers.isNullOrEmpty()) {
 | 
					    if (!markers.isNullOrEmpty()) super.paint(g) else Unit
 | 
				
			||||||
      super.paint(g)
 | 
					
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  override fun paintChildren(g: Graphics) {
 | 
					  override fun paintChildren(g: Graphics) {
 | 
				
			||||||
    super.paintChildren(g)
 | 
					    super.paintChildren(g)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    val markers = markers ?: return
 | 
					    val markers = markers ?: return
 | 
				
			||||||
    val font = TagFont(editor)
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    val cache = EditorOffsetCache.new()
 | 
					 | 
				
			||||||
    val viewRange = StandardBoundaries.VISIBLE_ON_SCREEN.getOffsetRange(editor, cache)
 | 
					 | 
				
			||||||
    val occupied = mutableListOf<Rectangle>()
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    (g as Graphics2D).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
 | 
					    (g as Graphics2D).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // If there is a tag at the caret location, prioritize its rendering over all other tags. This is helpful for seeing which tag is
 | 
					    val font = TagFont(editor)
 | 
				
			||||||
    // currently selected while navigating highly clustered tags, although it does end up rearranging nearby tags which can be confusing.
 | 
					
 | 
				
			||||||
    
 | 
					    val cache = EditorOffsetCache.new()
 | 
				
			||||||
    // TODO instead of immediately painting, we could calculate the layout of everything first, and then remove tags that interfere with
 | 
					    val viewRange = VISIBLE_ON_SCREEN.getOffsetRange(editor, cache)
 | 
				
			||||||
    //      the caret tag to avoid changing the alignment of the caret tag
 | 
					    val occupied = mutableListOf<Rectangle>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // If there is a tag at the caret location, prioritize its rendering over
 | 
				
			||||||
 | 
					    // all other tags. This is helpful for seeing which tag is currently
 | 
				
			||||||
 | 
					    // selected while navigating highly clustered tags, although it does end
 | 
				
			||||||
 | 
					    // up rearranging nearby tags which can be confusing.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO: instead of immediately painting, we could calculate the layout
 | 
				
			||||||
 | 
					    //  of everything first, and then remove tags that interfere with
 | 
				
			||||||
 | 
					    //  the caret tag to avoid changing the alignment of the caret tag
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    val caretOffset = editor.caretModel.offset
 | 
					    val caretOffset = editor.caretModel.offset
 | 
				
			||||||
    val caretMarker = markers.find { it.offsetL == caretOffset || it.offsetR == caretOffset }
 | 
					    val caretMarker = markers.find { it.offsetL == caretOffset || it.offsetR == caretOffset }
 | 
				
			||||||
    caretMarker?.paint(g, editor, cache, font, occupied)
 | 
					    caretMarker?.paint(g, editor, cache, font, occupied)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    for (marker in markers) {
 | 
					    for (marker in markers)
 | 
				
			||||||
      if (marker.isOffsetInRange(viewRange) && marker !== caretMarker) {
 | 
					      if (marker.isOffsetInRange(viewRange) && marker !== caretMarker)
 | 
				
			||||||
        marker.paint(g, editor, cache, font, occupied)
 | 
					        marker.paint(g, editor, cache, font, occupied)
 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +1,20 @@
 | 
				
			|||||||
package org.acejump.view
 | 
					package org.acejump.view
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
import com.intellij.openapi.editor.colors.EditorFontType
 | 
					import com.intellij.openapi.editor.colors.EditorFontType.BOLD
 | 
				
			||||||
 | 
					import com.intellij.openapi.editor.colors.EditorFontType.PLAIN
 | 
				
			||||||
import java.awt.Font
 | 
					import java.awt.Font
 | 
				
			||||||
import java.awt.FontMetrics
 | 
					import java.awt.FontMetrics
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Stores font metrics for aligning and rendering [Tag]s.
 | 
					 * Stores font metrics for aligning and rendering [TagMarker]s.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal class TagFont(editor: Editor) {
 | 
					class TagFont(editor: Editor) {
 | 
				
			||||||
  val tagFont: Font = editor.colorsScheme.getFont(EditorFontType.BOLD)
 | 
					  val tagFont: Font = editor.colorsScheme.getFont(BOLD)
 | 
				
			||||||
  val tagCharWidth = editor.component.getFontMetrics(tagFont).charWidth('W')
 | 
					  val tagCharWidth = editor.component.getFontMetrics(tagFont).charWidth('W')
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  val editorFontMetrics: FontMetrics = editor.component.getFontMetrics(editor.colorsScheme.getFont(EditorFontType.PLAIN))
 | 
					  val editorFontMetrics: FontMetrics =
 | 
				
			||||||
 | 
					    editor.component.getFontMetrics(editor.colorsScheme.getFont(PLAIN))
 | 
				
			||||||
  val lineHeight = editor.lineHeight
 | 
					  val lineHeight = editor.lineHeight
 | 
				
			||||||
  val baselineDistance = editor.ascent
 | 
					  val baselineDistance = editor.ascent
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,9 +2,10 @@ package org.acejump.view
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
import com.intellij.ui.ColorUtil
 | 
					import com.intellij.ui.ColorUtil
 | 
				
			||||||
 | 
					import com.intellij.ui.JreHiDpiUtil
 | 
				
			||||||
import com.intellij.ui.scale.JBUIScale
 | 
					import com.intellij.ui.scale.JBUIScale
 | 
				
			||||||
import org.acejump.boundaries.EditorOffsetCache
 | 
					import org.acejump.boundaries.EditorOffsetCache
 | 
				
			||||||
import org.acejump.boundaries.StandardBoundaries
 | 
					import org.acejump.boundaries.StandardBoundaries.VISIBLE_ON_SCREEN
 | 
				
			||||||
import org.acejump.config.AceConfig
 | 
					import org.acejump.config.AceConfig
 | 
				
			||||||
import org.acejump.countMatchingCharacters
 | 
					import org.acejump.countMatchingCharacters
 | 
				
			||||||
import org.acejump.immutableText
 | 
					import org.acejump.immutableText
 | 
				
			||||||
@@ -17,7 +18,7 @@ import kotlin.math.max
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Describes a 1 or 2 character shortcut that points to a specific character in the editor.
 | 
					 * Describes a 1 or 2 character shortcut that points to a specific character in the editor.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal class Tag(
 | 
					class TagMarker(
 | 
				
			||||||
  private val tag: String,
 | 
					  private val tag: String,
 | 
				
			||||||
  val offsetL: Int,
 | 
					  val offsetL: Int,
 | 
				
			||||||
  val offsetR: Int,
 | 
					  val offsetR: Int,
 | 
				
			||||||
@@ -25,103 +26,108 @@ internal class Tag(
 | 
				
			|||||||
  private val hasSpaceRight: Boolean
 | 
					  private val hasSpaceRight: Boolean
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  private val length = tag.length
 | 
					  private val length = tag.length
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  companion object {
 | 
					  companion object {
 | 
				
			||||||
    private const val ARC = 1
 | 
					    private const val ARC = 1
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Creates a new tag, precomputing some information about the nearby characters to reduce rendering overhead. If the last typed
 | 
					     * Creates a new tag, precomputing some information about the nearby characters to reduce rendering overhead. If the last typed
 | 
				
			||||||
     * character ([literalQueryText]) matches the first [tag] character, only the second [tag] character is displayed.
 | 
					     * character ([literalQueryText]) matches the first [tag] character, only the second [tag] character is displayed.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    fun create(editor: Editor, tag: String, offset: Int, literalQueryText: String?): Tag {
 | 
					    fun create(editor: Editor, tag: String, offset: Int, literalQueryText: String?): TagMarker {
 | 
				
			||||||
      val chars = editor.immutableText
 | 
					      val chars = editor.immutableText
 | 
				
			||||||
      val matching = literalQueryText?.let { chars.countMatchingCharacters(offset, it) } ?: 0
 | 
					      val matching = literalQueryText?.let { chars.countMatchingCharacters(offset, it) } ?: 0
 | 
				
			||||||
      val hasSpaceRight = offset + 1 >= chars.length || chars[offset + 1].isWhitespace()
 | 
					      val hasSpaceRight = offset + 1 >= chars.length || chars[offset + 1].isWhitespace()
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      val displayedTag = if (literalQueryText != null && literalQueryText.last().equals(tag.first(), ignoreCase = true))
 | 
					      val displayedTag = if (literalQueryText != null && literalQueryText.last().equals(tag.first(), ignoreCase = true))
 | 
				
			||||||
        tag.drop(1).toUpperCase()
 | 
					        tag.drop(1).uppercase()
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
        tag.toUpperCase()
 | 
					        tag.uppercase()
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      return Tag(displayedTag, offset, offset + max(0, matching - 1), tag.length - displayedTag.length, hasSpaceRight)
 | 
					      return TagMarker(displayedTag, offset, offset + max(0, matching - 1), tag.length - displayedTag.length, hasSpaceRight)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Renders the tag background.
 | 
					     * Renders the tag background.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private fun drawHighlight(g: Graphics2D, rect: Rectangle, color: Color) {
 | 
					    private fun drawHighlight(g: Graphics2D, rect: Rectangle, color: Color) {
 | 
				
			||||||
      g.color = color
 | 
					      g.color = color
 | 
				
			||||||
      g.fillRoundRect(rect.x, rect.y, rect.width, rect.height + 1, ARC, ARC)
 | 
					      
 | 
				
			||||||
 | 
					      // Workaround for misalignment on high DPI screens.
 | 
				
			||||||
 | 
					      if (JreHiDpiUtil.isJreHiDPI(g)) {
 | 
				
			||||||
 | 
					        g.translate(0.0, -0.5)
 | 
				
			||||||
 | 
					        g.fillRoundRect(rect.x, rect.y, rect.width, rect.height + 1, ARC, ARC)
 | 
				
			||||||
 | 
					        g.translate(0.0, 0.5)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      else {
 | 
				
			||||||
 | 
					        g.fillRoundRect(rect.x, rect.y, rect.width, rect.height + 1, ARC, ARC)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Renders the tag text.
 | 
					     * Renders the tag text.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private fun drawForeground(g: Graphics2D, font: TagFont, point: Point, text: String) {
 | 
					    private fun drawForeground(g: Graphics2D, font: TagFont, point: Point, text: String) {
 | 
				
			||||||
      val x = point.x + 2
 | 
					      val x = point.x + 2
 | 
				
			||||||
      val y = point.y + font.baselineDistance
 | 
					      val y = point.y + font.baselineDistance
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
      g.font = font.tagFont
 | 
					      g.font = font.tagFont
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      if (!ColorUtil.isDark(AceConfig.tagForegroundColor)) {
 | 
					      if (!ColorUtil.isDark(AceConfig.tagForegroundColor)) {
 | 
				
			||||||
        g.color = Color(0F, 0F, 0F, 0.35F)
 | 
					        g.color = Color(0F, 0F, 0F, 0.35F)
 | 
				
			||||||
        g.drawString(text, x + 1, y + 1)
 | 
					        g.drawString(text, x + 1, y + 1)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      g.color = AceConfig.tagForegroundColor
 | 
					      g.color = AceConfig.tagForegroundColor
 | 
				
			||||||
      g.drawString(text, x, y)
 | 
					      g.drawString(text, x, y)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Returns true if the left-aligned offset is in the range. Use to cull tags outside visible range.
 | 
					   * Returns true if the left-aligned offset is in the range. Use to cull tags outside visible range.
 | 
				
			||||||
   * Only the left offset is checked, because if the tag was right-aligned on the last index of the range, it would not be visible anyway.
 | 
					   * Only the left offset is checked, because if the tag was right-aligned on the last index of the range, it would not be visible anyway.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun isOffsetInRange(range: IntRange): Boolean {
 | 
					  fun isOffsetInRange(range: IntRange): Boolean = offsetL in range
 | 
				
			||||||
    return offsetL in range
 | 
					
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Paints the tag, taking into consideration visual space around characters in the editor, as well as all other previously painted tags.
 | 
					   * Paints the tag, taking into consideration visual space around characters in the editor, as well as all other previously painted tags.
 | 
				
			||||||
   * Returns a rectangle indicating the area where the tag was rendered, or null if the tag could not be rendered due to overlap.
 | 
					   * Returns a rectangle indicating the area where the tag was rendered, or null if the tag could not be rendered due to overlap.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun paint(g: Graphics2D, editor: Editor, cache: EditorOffsetCache, font: TagFont, occupied: MutableList<Rectangle>): Rectangle? {
 | 
					  fun paint(g: Graphics2D, editor: Editor, cache: EditorOffsetCache, font: TagFont, occupied: MutableList<Rectangle>): Rectangle? {
 | 
				
			||||||
    val rect = alignTag(editor, cache, font, occupied) ?: return null
 | 
					    val rect = alignTag(editor, cache, font, occupied) ?: return null
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    drawHighlight(g, rect, AceConfig.tagBackgroundColor)
 | 
					    drawHighlight(g, rect, AceConfig.tagBackgroundColor)
 | 
				
			||||||
    drawForeground(g, font, rect.location, tag)
 | 
					    drawForeground(g, font, rect.location, tag)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    occupied.add(JBUIScale.scale(2).let { Rectangle(rect.x - it, rect.y, rect.width + (2 * it), rect.height) })
 | 
					    occupied.add(JBUIScale.scale(2).let { Rectangle(rect.x - it, rect.y, rect.width + (2 * it), rect.height) })
 | 
				
			||||||
    return rect
 | 
					    return rect
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private fun alignTag(editor: Editor, cache: EditorOffsetCache, font: TagFont, occupied: List<Rectangle>): Rectangle? {
 | 
					  private fun alignTag(editor: Editor, cache: EditorOffsetCache, font: TagFont, occupied: List<Rectangle>): Rectangle? {
 | 
				
			||||||
    val boundaries = StandardBoundaries.VISIBLE_ON_SCREEN
 | 
					    val boundaries = VISIBLE_ON_SCREEN
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (hasSpaceRight || offsetL == 0 || editor.immutableText[offsetL - 1].let { it == '\n' || it == '\r' }) {
 | 
					    if (hasSpaceRight || offsetL == 0 || editor.immutableText[offsetL - 1].let { it == '\n' || it == '\r' }) {
 | 
				
			||||||
      val rectR = createRightAlignedTagRect(editor, cache, font)
 | 
					      val rectR = createRightAlignedTagRect(editor, cache, font)
 | 
				
			||||||
      return rectR.takeIf { boundaries.isOffsetInside(editor, offsetR, cache) && occupied.none(rectR::intersects) }
 | 
					      return rectR.takeIf { boundaries.isOffsetInside(editor, offsetR, cache) && occupied.none(rectR::intersects) }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    val rectL = createLeftAlignedTagRect(editor, cache, font)
 | 
					    val rectL = createLeftAlignedTagRect(editor, cache, font)
 | 
				
			||||||
    if (occupied.none(rectL::intersects)) {
 | 
					    if (occupied.none(rectL::intersects))
 | 
				
			||||||
      return rectL.takeIf { boundaries.isOffsetInside(editor, offsetL, cache) }
 | 
					      return rectL.takeIf { boundaries.isOffsetInside(editor, offsetL, cache) }
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    val rectR = createRightAlignedTagRect(editor, cache, font)
 | 
					    val rectR = createRightAlignedTagRect(editor, cache, font)
 | 
				
			||||||
    if (occupied.none(rectR::intersects)) {
 | 
					    if (occupied.none(rectR::intersects))
 | 
				
			||||||
      return rectR.takeIf { boundaries.isOffsetInside(editor, offsetR, cache) }
 | 
					      return rectR.takeIf { boundaries.isOffsetInside(editor, offsetR, cache) }
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    return null
 | 
					    return null
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private fun createRightAlignedTagRect(editor: Editor, cache: EditorOffsetCache, font: TagFont): Rectangle {
 | 
					  private fun createRightAlignedTagRect(editor: Editor, cache: EditorOffsetCache, font: TagFont): Rectangle {
 | 
				
			||||||
    val pos = cache.offsetToXY(editor, offsetR)
 | 
					    val pos = cache.offsetToXY(editor, offsetR)
 | 
				
			||||||
    val shift = font.editorFontMetrics.charWidth(editor.immutableText[offsetR]) + (font.tagCharWidth * shiftR)
 | 
					    val shift = font.editorFontMetrics.charWidth(editor.immutableText[offsetR]) + (font.tagCharWidth * shiftR)
 | 
				
			||||||
    return Rectangle(pos.x + shift, pos.y, (font.tagCharWidth * length) + 4, font.lineHeight)
 | 
					    return Rectangle(pos.x + shift, pos.y, (font.tagCharWidth * length) + 4, font.lineHeight)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private fun createLeftAlignedTagRect(editor: Editor, cache: EditorOffsetCache, font: TagFont): Rectangle {
 | 
					  private fun createLeftAlignedTagRect(editor: Editor, cache: EditorOffsetCache, font: TagFont): Rectangle {
 | 
				
			||||||
    val pos = cache.offsetToXY(editor, offsetL)
 | 
					    val pos = cache.offsetToXY(editor, offsetL)
 | 
				
			||||||
    val shift = -(font.tagCharWidth * length)
 | 
					    val shift = -(font.tagCharWidth * length)
 | 
				
			||||||
@@ -1,140 +1,220 @@
 | 
				
			|||||||
package org.acejump.view
 | 
					package org.acejump.view
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.intellij.codeInsight.CodeInsightBundle
 | 
				
			||||||
 | 
					import com.intellij.codeInsight.hint.*
 | 
				
			||||||
 | 
					import com.intellij.codeInsight.hint.HintManagerImpl.HIDE_BY_ESCAPE
 | 
				
			||||||
 | 
					import com.intellij.codeInsight.hint.HintManagerImpl.HIDE_BY_TEXT_CHANGE
 | 
				
			||||||
import com.intellij.openapi.editor.Editor
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
import com.intellij.openapi.editor.colors.EditorFontType
 | 
					import com.intellij.openapi.editor.colors.EditorFontType
 | 
				
			||||||
import com.intellij.openapi.editor.markup.CustomHighlighterRenderer
 | 
					import com.intellij.openapi.editor.markup.*
 | 
				
			||||||
import com.intellij.openapi.editor.markup.HighlighterLayer
 | 
					import com.intellij.openapi.editor.markup.HighlighterTargetArea.EXACT_RANGE
 | 
				
			||||||
import com.intellij.openapi.editor.markup.HighlighterTargetArea
 | 
					import com.intellij.ui.*
 | 
				
			||||||
import com.intellij.openapi.editor.markup.RangeHighlighter
 | 
					import com.intellij.util.ui.*
 | 
				
			||||||
import com.intellij.util.ui.JBUI
 | 
					 | 
				
			||||||
import it.unimi.dsi.fastutil.ints.IntList
 | 
					import it.unimi.dsi.fastutil.ints.IntList
 | 
				
			||||||
 | 
					import org.acejump.*
 | 
				
			||||||
import org.acejump.boundaries.EditorOffsetCache
 | 
					import org.acejump.boundaries.EditorOffsetCache
 | 
				
			||||||
import org.acejump.config.AceConfig
 | 
					import org.acejump.config.AceConfig
 | 
				
			||||||
import org.acejump.immutableText
 | 
					 | 
				
			||||||
import org.acejump.input.JumpMode
 | 
					import org.acejump.input.JumpMode
 | 
				
			||||||
import org.acejump.isWordPart
 | 
					 | 
				
			||||||
import org.acejump.search.SearchQuery
 | 
					import org.acejump.search.SearchQuery
 | 
				
			||||||
import org.acejump.wordEnd
 | 
					import java.awt.*
 | 
				
			||||||
import org.acejump.wordStart
 | 
					import javax.swing.*
 | 
				
			||||||
import java.awt.Graphics
 | 
					 | 
				
			||||||
import kotlin.math.max
 | 
					import kotlin.math.max
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Renders highlights for search occurrences.
 | 
					 * Renders highlights for search occurrences.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
internal class TextHighlighter(private val editor: Editor) {
 | 
					internal class TextHighlighter {
 | 
				
			||||||
  private companion object {
 | 
					  private companion object { private const val LAYER = HighlighterLayer.LAST + 1 }
 | 
				
			||||||
    private const val LAYER = HighlighterLayer.LAST + 1
 | 
					  private var previousHighlights = mutableMapOf<Editor, Array<RangeHighlighter>>()
 | 
				
			||||||
  }
 | 
					  private var previousHint: LightweightHint? = null
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private var previousHighlights: Array<RangeHighlighter>? = null
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Removes all current highlights and re-creates them from scratch. Must be called whenever any of the method parameters change.
 | 
					   * Label for the search notification.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun render(offsets: IntList, query: SearchQuery, jumpMode: JumpMode) {
 | 
					  private class NotificationLabel constructor(text: String?): JLabel(text) {
 | 
				
			||||||
    val markup = editor.markupModel
 | 
					    init {
 | 
				
			||||||
    val chars = editor.immutableText
 | 
					      background = HintUtil.getInformationColor()
 | 
				
			||||||
    
 | 
					      foreground = JBColor.foreground()
 | 
				
			||||||
 | 
					      this.isOpaque = true
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Removes all current highlights and re-creates them from scratch.
 | 
				
			||||||
 | 
					   * Must be called whenever any of the method parameters change.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  fun render(results: Map<Editor, IntList>, query: SearchQuery, jumpMode: JumpMode) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    val renderer = when {
 | 
					    val renderer = when {
 | 
				
			||||||
      query is SearchQuery.RegularExpression -> RegexRenderer
 | 
					      query is SearchQuery.RegularExpression -> RegexRenderer
 | 
				
			||||||
      jumpMode === JumpMode.TARGET           -> SearchedWordWithOutlineRenderer
 | 
					      jumpMode === JumpMode.TARGET -> SearchedWordWithOutlineRenderer
 | 
				
			||||||
      else                                   -> SearchedWordRenderer
 | 
					      else -> SearchedWordRenderer
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    val modifications = (previousHighlights?.size ?: 0) + offsets.size
 | 
					    for ((editor, offsets) in results) {
 | 
				
			||||||
    val enableBulkEditing = modifications > 1000
 | 
					      val highlights = previousHighlights[editor]
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    val document = editor.document
 | 
					      val markup = editor.markupModel
 | 
				
			||||||
    
 | 
					      val document = editor.document
 | 
				
			||||||
    try {
 | 
					      val chars = editor.immutableText
 | 
				
			||||||
      if (enableBulkEditing) {
 | 
					
 | 
				
			||||||
        document.isInBulkUpdate = true
 | 
					      val modifications = (highlights?.size ?: 0) + offsets.size
 | 
				
			||||||
      }
 | 
					      val enableBulkEditing = modifications > 1000
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      previousHighlights?.forEach(markup::removeHighlighter)
 | 
					      try {
 | 
				
			||||||
      previousHighlights = Array(offsets.size) { index ->
 | 
					        if (enableBulkEditing) document.isInBulkUpdate = true
 | 
				
			||||||
        val start = offsets.getInt(index)
 | 
					
 | 
				
			||||||
        val end = start + query.getHighlightLength(chars, start)
 | 
					        highlights?.forEach(markup::removeHighlighter)
 | 
				
			||||||
        
 | 
					        previousHighlights[editor] = Array(offsets.size) { index ->
 | 
				
			||||||
        markup.addRangeHighlighter(start, end, LAYER, null, HighlighterTargetArea.EXACT_RANGE).apply {
 | 
					          val start = offsets.getInt(index)
 | 
				
			||||||
          customRenderer = renderer
 | 
					          val end = start + query.getHighlightLength(chars, start)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          markup.addRangeHighlighter(start, end, LAYER, null, EXACT_RANGE)
 | 
				
			||||||
 | 
					            .apply { customRenderer = renderer }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      } finally {
 | 
				
			||||||
    } finally {
 | 
					        if (enableBulkEditing) document.isInBulkUpdate = false
 | 
				
			||||||
      if (enableBulkEditing) {
 | 
					 | 
				
			||||||
        document.isInBulkUpdate = false
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (AceConfig.showSearchNotification)
 | 
				
			||||||
 | 
					      showSearchNotification(results, query, jumpMode)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (editor in previousHighlights.keys.toList()) {
 | 
				
			||||||
 | 
					      if (!results.containsKey(editor))
 | 
				
			||||||
 | 
					        previousHighlights.remove(editor)
 | 
				
			||||||
 | 
					          ?.forEach(editor.markupModel::removeHighlighter)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Show a notification with the current search text.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  private fun showSearchNotification(results: Map<Editor, IntList>,
 | 
				
			||||||
 | 
					                                     query: SearchQuery, jumpMode: JumpMode) {
 | 
				
			||||||
 | 
					    // clear previous hint
 | 
				
			||||||
 | 
					    previousHint?.hide()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // add notification hint to first editor
 | 
				
			||||||
 | 
					    results.keys.first().let {
 | 
				
			||||||
 | 
					      val component: JComponent = it.component
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      val label1: JLabel = NotificationLabel(" " +
 | 
				
			||||||
 | 
					        CodeInsightBundle.message("incremental.search.tooltip.prefix"))
 | 
				
			||||||
 | 
					      label1.font = UIUtil.getLabelFont().deriveFont(Font.BOLD)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      val queryText = " " +
 | 
				
			||||||
 | 
					        if (query is SearchQuery.RegularExpression) query.toRegex().toString()
 | 
				
			||||||
 | 
					        else query.rawText[0] + query.rawText.drop(1).lowercase()
 | 
				
			||||||
 | 
					      val label2 = NotificationLabel(queryText)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      val label3 = NotificationLabel(
 | 
				
			||||||
 | 
					        "Found ${results.values.flatMap { it.asIterable() }.size}" +
 | 
				
			||||||
 | 
					        " results in ${results.keys.size}" +
 | 
				
			||||||
 | 
					        " editor" + if(1 != results.keys.size) "s" else "."
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      val panel = JPanel(BorderLayout()).apply {
 | 
				
			||||||
 | 
					        add(label1, BorderLayout.WEST)
 | 
				
			||||||
 | 
					        add(label2, BorderLayout.CENTER)
 | 
				
			||||||
 | 
					        add(label3, BorderLayout.EAST)
 | 
				
			||||||
 | 
					        border = BorderFactory.createLineBorder(
 | 
				
			||||||
 | 
					          if (jumpMode == JumpMode.DISABLED) Color.BLACK else jumpMode.caretColor
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        preferredSize = Dimension(it.contentComponent.width +
 | 
				
			||||||
 | 
					          label1.preferredSize.width, preferredSize.height)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      val hint = LightweightHint(panel)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      val x = SwingUtilities.convertPoint(component, 0, 0, component).x
 | 
				
			||||||
 | 
					      val y: Int = -hint.component.preferredSize.height
 | 
				
			||||||
 | 
					      val p = SwingUtilities.convertPoint(component, x, y,
 | 
				
			||||||
 | 
					        component.rootPane.layeredPane)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      HintManagerImpl.getInstanceImpl().showEditorHint(
 | 
				
			||||||
 | 
					        hint,
 | 
				
			||||||
 | 
					        it,
 | 
				
			||||||
 | 
					        p,
 | 
				
			||||||
 | 
					        HIDE_BY_ESCAPE or HIDE_BY_TEXT_CHANGE,
 | 
				
			||||||
 | 
					        0,
 | 
				
			||||||
 | 
					        false,
 | 
				
			||||||
 | 
					        HintHint(it, p).setAwtTooltip(false)
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					      previousHint = hint
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun reset() {
 | 
					  fun reset() {
 | 
				
			||||||
    editor.markupModel.removeAllHighlighters()
 | 
					    previousHighlights.keys.forEach { it.markupModel.removeAllHighlighters() }
 | 
				
			||||||
    previousHighlights = null
 | 
					    previousHighlights.clear()
 | 
				
			||||||
 | 
					    previousHint?.hide()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Renders a filled highlight in the background of a searched text occurrence.
 | 
					   * Renders a filled highlight in the background of a searched text occurrence.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  private object SearchedWordRenderer : CustomHighlighterRenderer {
 | 
					  private object SearchedWordRenderer: CustomHighlighterRenderer {
 | 
				
			||||||
    override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) {
 | 
					    override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) =
 | 
				
			||||||
      drawFilled(g, editor, highlighter.startOffset, highlighter.endOffset)
 | 
					      drawFilled(g, editor, highlighter.startOffset, highlighter.endOffset)
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    private fun drawFilled(g: Graphics, editor: Editor, startOffset: Int, endOffset: Int) {
 | 
					    private fun drawFilled(g: Graphics, editor: Editor, startOffset: Int, endOffset: Int) {
 | 
				
			||||||
      val start = EditorOffsetCache.Uncached.offsetToXY(editor, startOffset)
 | 
					      val start = EditorOffsetCache.Uncached.offsetToXY(editor, startOffset)
 | 
				
			||||||
      val end = EditorOffsetCache.Uncached.offsetToXY(editor, endOffset)
 | 
					      val end = EditorOffsetCache.Uncached.offsetToXY(editor, endOffset)
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      g.color = AceConfig.textHighlightColor
 | 
					      g.color = AceConfig.textHighlightColor
 | 
				
			||||||
      g.fillRect(start.x, start.y + 1, end.x - start.x, editor.lineHeight - 1)
 | 
					      g.fillRect(start.x, start.y, end.x - start.x, editor.lineHeight)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
      g.color = AceConfig.tagBackgroundColor
 | 
					      g.color = AceConfig.tagBackgroundColor
 | 
				
			||||||
      g.drawRect(start.x, start.y, end.x - start.x, editor.lineHeight)
 | 
					      g.drawRect(start.x, start.y, end.x - start.x, editor.lineHeight)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Renders a filled highlight in the background of a searched text occurrence, as well as an outline indicating the range of characters
 | 
					   * Renders a filled highlight in the background of a searched
 | 
				
			||||||
   * that will be selected by [JumpMode.TARGET].
 | 
					   * text occurrence, as well as an outline indicating the range
 | 
				
			||||||
 | 
					   * of characters that will be selected by [JumpMode.TARGET].
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  private object SearchedWordWithOutlineRenderer : CustomHighlighterRenderer {
 | 
					  private object SearchedWordWithOutlineRenderer: CustomHighlighterRenderer {
 | 
				
			||||||
    override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) {
 | 
					    override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) {
 | 
				
			||||||
      SearchedWordRenderer.paint(editor, highlighter, g)
 | 
					      SearchedWordRenderer.paint(editor, highlighter, g)
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      val chars = editor.immutableText
 | 
					      val chars = editor.immutableText
 | 
				
			||||||
      val startOffset = highlighter.startOffset
 | 
					      val startOffset = highlighter.startOffset
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      if (chars.getOrNull(startOffset)?.isWordPart == true) {
 | 
					      if (chars.getOrNull(startOffset)?.isWordPart == true)
 | 
				
			||||||
        drawOutline(g, editor, chars.wordStart(startOffset), chars.wordEnd(startOffset) + 1)
 | 
					        drawOutline(g, editor, chars.wordStart(startOffset), chars.wordEnd(startOffset) + 1)
 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    private fun drawOutline(g: Graphics, editor: Editor, startOffset: Int, endOffset: Int) {
 | 
					    private fun drawOutline(g: Graphics, editor: Editor, startOffset: Int, endOffset: Int) {
 | 
				
			||||||
      val start = EditorOffsetCache.Uncached.offsetToXY(editor, startOffset)
 | 
					      val start = EditorOffsetCache.Uncached.offsetToXY(editor, startOffset)
 | 
				
			||||||
      val end = EditorOffsetCache.Uncached.offsetToXY(editor, endOffset)
 | 
					      val end = EditorOffsetCache.Uncached.offsetToXY(editor, endOffset)
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      g.color = AceConfig.targetModeColor
 | 
					      g.color = AceConfig.targetModeColor
 | 
				
			||||||
      g.drawRect(max(0, start.x - JBUI.scale(1)), start.y, end.x - start.x + JBUI.scale(2), editor.lineHeight)
 | 
					      g.drawRect(max(0, start.x - JBUI.scale(1)), start.y,
 | 
				
			||||||
 | 
					        end.x - start.x + JBUI.scale(2), editor.lineHeight)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Renders a filled highlight in the background of the first highlighted position. Used for regex search queries.
 | 
					   * Renders a filled highlight in the background of the first highlighted
 | 
				
			||||||
 | 
					   * position. Used for regex search queries.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  private object RegexRenderer : CustomHighlighterRenderer {
 | 
					  private object RegexRenderer: CustomHighlighterRenderer {
 | 
				
			||||||
    override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) {
 | 
					    override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) =
 | 
				
			||||||
      drawSingle(g, editor, highlighter.startOffset)
 | 
					      drawSingle(g, editor, highlighter.startOffset)
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    private fun drawSingle(g: Graphics, editor: Editor, offset: Int) {
 | 
					    private fun drawSingle(g: Graphics, editor: Editor, offset: Int) {
 | 
				
			||||||
      val pos = EditorOffsetCache.Uncached.offsetToXY(editor, offset)
 | 
					      val pos = EditorOffsetCache.Uncached.offsetToXY(editor, offset)
 | 
				
			||||||
      val char = editor.immutableText.getOrNull(offset)?.takeUnless { it == '\n' || it == '\t' } ?: ' '
 | 
					      val char = editor.immutableText.getOrNull(offset)
 | 
				
			||||||
 | 
					        ?.takeUnless { it == '\n' || it == '\t' } ?: ' '
 | 
				
			||||||
      val font = editor.colorsScheme.getFont(EditorFontType.PLAIN)
 | 
					      val font = editor.colorsScheme.getFont(EditorFontType.PLAIN)
 | 
				
			||||||
      val lastCharWidth = editor.component.getFontMetrics(font).charWidth(char)
 | 
					      val lastCharWidth = editor.component.getFontMetrics(font).charWidth(char)
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      g.color = AceConfig.textHighlightColor
 | 
					      g.color = AceConfig.textHighlightColor
 | 
				
			||||||
      g.fillRect(pos.x, pos.y + 1, lastCharWidth, editor.lineHeight - 1)
 | 
					      g.fillRect(pos.x, pos.y, lastCharWidth, editor.lineHeight)
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      g.color = AceConfig.tagBackgroundColor
 | 
					      g.color = AceConfig.tagBackgroundColor
 | 
				
			||||||
      g.drawRect(pos.x, pos.y, lastCharWidth, editor.lineHeight)
 | 
					      g.drawRect(pos.x, pos.y, lastCharWidth, editor.lineHeight)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,10 @@
 | 
				
			|||||||
                         implementationClass="org.acejump.action.AceEditorAction$SelectBackward"/>
 | 
					                         implementationClass="org.acejump.action.AceEditorAction$SelectBackward"/>
 | 
				
			||||||
    <editorActionHandler action="EditorEnter" order="first"
 | 
					    <editorActionHandler action="EditorEnter" order="first"
 | 
				
			||||||
                         implementationClass="org.acejump.action.AceEditorAction$SelectForward"/>
 | 
					                         implementationClass="org.acejump.action.AceEditorAction$SelectForward"/>
 | 
				
			||||||
 | 
					    <editorActionHandler action="EditorTab" order="first"
 | 
				
			||||||
 | 
					                         implementationClass="org.acejump.action.AceEditorAction$ScrollToNextScreenful"/>
 | 
				
			||||||
 | 
					    <editorActionHandler action="EditorUnindentSelection" order="first"
 | 
				
			||||||
 | 
					                         implementationClass="org.acejump.action.AceEditorAction$ScrollToPreviousScreenful"/>
 | 
				
			||||||
    <editorActionHandler action="EditorUp" order="first"
 | 
					    <editorActionHandler action="EditorUp" order="first"
 | 
				
			||||||
                         implementationClass="org.acejump.action.AceEditorAction$SearchLineStarts"/>
 | 
					                         implementationClass="org.acejump.action.AceEditorAction$SearchLineStarts"/>
 | 
				
			||||||
    <editorActionHandler action="EditorLeft" order="first"
 | 
					    <editorActionHandler action="EditorLeft" order="first"
 | 
				
			||||||
@@ -37,6 +41,7 @@
 | 
				
			|||||||
                         implementationClass="org.acejump.action.AceEditorAction$SearchLineEnds"/>
 | 
					                         implementationClass="org.acejump.action.AceEditorAction$SearchLineEnds"/>
 | 
				
			||||||
    <editorActionHandler action="EditorLineEnd" order="first"
 | 
					    <editorActionHandler action="EditorLineEnd" order="first"
 | 
				
			||||||
                         implementationClass="org.acejump.action.AceEditorAction$SearchLineEnds"/>
 | 
					                         implementationClass="org.acejump.action.AceEditorAction$SearchLineEnds"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  </extensions>
 | 
					  </extensions>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <actions>
 | 
					  <actions>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,8 @@
 | 
				
			|||||||
import com.intellij.openapi.actionSystem.IdeActions.ACTION_EDITOR_ENTER
 | 
					import com.intellij.openapi.actionSystem.IdeActions.ACTION_EDITOR_ENTER
 | 
				
			||||||
import com.intellij.openapi.actionSystem.IdeActions.ACTION_EDITOR_START_NEW_LINE
 | 
					import com.intellij.openapi.actionSystem.IdeActions.ACTION_EDITOR_START_NEW_LINE
 | 
				
			||||||
 | 
					import com.intellij.openapi.editor.actions.EnterAction
 | 
				
			||||||
import org.acejump.action.AceAction
 | 
					import org.acejump.action.AceAction
 | 
				
			||||||
 | 
					import org.acejump.config.AceConfig
 | 
				
			||||||
import org.acejump.test.util.BaseTest
 | 
					import org.acejump.test.util.BaseTest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@@ -63,7 +65,7 @@ class AceTest : BaseTest() {
 | 
				
			|||||||
  fun `test shift selection`() {
 | 
					  fun `test shift selection`() {
 | 
				
			||||||
    "<caret>testing 1234".search("4")
 | 
					    "<caret>testing 1234".search("4")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    typeAndWaitForResults(session.tags[0].key.toUpperCase())
 | 
					    typeAndWaitForResults(session.tags[0].key.uppercase())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    myFixture.checkResult("<selection>testing 123<caret></selection>4")
 | 
					    myFixture.checkResult("<selection>testing 123<caret></selection>4")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -71,7 +73,7 @@ class AceTest : BaseTest() {
 | 
				
			|||||||
  fun `test words before caret action`() {
 | 
					  fun `test words before caret action`() {
 | 
				
			||||||
    makeEditor("test words <caret> before caret is two")
 | 
					    makeEditor("test words <caret> before caret is two")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    takeAction(AceAction.StartAllWordsBackwardsMode)
 | 
					    takeAction(AceAction.StartAllWordsBackwardsMode())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assertEquals(2, session.tags.size)
 | 
					    assertEquals(2, session.tags.size)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -79,7 +81,7 @@ class AceTest : BaseTest() {
 | 
				
			|||||||
  fun `test words after caret action`() {
 | 
					  fun `test words after caret action`() {
 | 
				
			||||||
    makeEditor("test words <caret> after caret is four")
 | 
					    makeEditor("test words <caret> after caret is four")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    takeAction(AceAction.StartAllWordsForwardMode)
 | 
					    takeAction(AceAction.StartAllWordsForwardMode())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assertEquals(4, session.tags.size)
 | 
					    assertEquals(4, session.tags.size)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -87,7 +89,7 @@ class AceTest : BaseTest() {
 | 
				
			|||||||
  fun `test word mode`() {
 | 
					  fun `test word mode`() {
 | 
				
			||||||
    makeEditor("test word action")
 | 
					    makeEditor("test word action")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    takeAction(AceAction.StartAllWordsMode)
 | 
					    takeAction(AceAction.StartAllWordsMode())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assertEquals(3, session.tags.size)
 | 
					    assertEquals(3, session.tags.size)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -99,17 +101,65 @@ class AceTest : BaseTest() {
 | 
				
			|||||||
  fun `test target mode`() {
 | 
					  fun `test target mode`() {
 | 
				
			||||||
    "<caret>test target action".search("target")
 | 
					    "<caret>test target action".search("target")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    takeAction(AceAction.ToggleTargetMode)
 | 
					    takeAction(AceAction.ToggleTargetMode())
 | 
				
			||||||
    typeAndWaitForResults(session.tags[0].key)
 | 
					    typeAndWaitForResults(session.tags[0].key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    myFixture.checkResult("test <selection>target<caret></selection> action")
 | 
					    myFixture.checkResult("test <selection>target<caret></selection> action")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun `test cache invalidation`() {
 | 
				
			||||||
 | 
					    "first line".search("first")
 | 
				
			||||||
 | 
					    typeAndWaitForResults(session.tags[0].key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    repeat(3) { takeAction(EnterAction()) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    takeAction(AceAction.ToggleTargetMode())
 | 
				
			||||||
 | 
					    typeAndWaitForResults("first")
 | 
				
			||||||
 | 
					    typeAndWaitForResults(session.tags[0].key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    myFixture.checkResult("\n\n\n<selection>first<caret></selection> line")
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun `test line mode`() {
 | 
					  fun `test line mode`() {
 | 
				
			||||||
    makeEditor("    test\n    three\n    lines\n")
 | 
					    makeEditor("    test\n    three\n    lines\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    takeAction(AceAction.StartAllLineMarksMode)
 | 
					    takeAction(AceAction.StartAllLineMarksMode())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assertEquals(8, session.tags.size) // last empty line does not count
 | 
					    assertEquals(8, session.tags.size) // last empty line does not count
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun `test chinese selection`() {
 | 
				
			||||||
 | 
					    AceConfig.settings.mapToASCII = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    "test 拼音 selection".search("py")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    takeAction(AceAction.ToggleTargetMode())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    typeAndWaitForResults(session.tags[0].key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    myFixture.checkResult("test <selection>拼音<caret></selection> selection")
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun `test japanese selection`() {
 | 
				
			||||||
 | 
					    AceConfig.settings.mapToASCII = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    "あみだにょらい".search("am")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    takeAction(AceAction.ToggleTargetMode())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    typeAndWaitForResults(session.tags[0].key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    myFixture.checkResult("<selection>あみだにょらい<caret></selection>")
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // https://github.com/acejump/AceJump/issues/355
 | 
				
			||||||
 | 
					  fun `ignore test a word that is difficult to tag`() {
 | 
				
			||||||
 | 
					    makeEditor("aaCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    takeAction(AceAction.ActivateOrCycleMode())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    typeAndWaitForResults("c")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assertEquals(2, session.tags.size)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										169
									
								
								src/test/kotlin/ExternalUsageTest.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										169
									
								
								src/test/kotlin/ExternalUsageTest.kt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,169 @@
 | 
				
			|||||||
 | 
					import com.intellij.mock.MockVirtualFile
 | 
				
			||||||
 | 
					import com.intellij.openapi.editor.Editor
 | 
				
			||||||
 | 
					import com.intellij.openapi.fileEditor.TextEditor
 | 
				
			||||||
 | 
					import com.intellij.util.ui.UIUtil
 | 
				
			||||||
 | 
					import it.unimi.dsi.fastutil.ints.IntArrayList
 | 
				
			||||||
 | 
					import junit.framework.TestCase
 | 
				
			||||||
 | 
					import org.acejump.action.AceAction
 | 
				
			||||||
 | 
					import org.acejump.boundaries.Boundaries
 | 
				
			||||||
 | 
					import org.acejump.boundaries.EditorOffsetCache
 | 
				
			||||||
 | 
					import org.acejump.boundaries.StandardBoundaries.WHOLE_FILE
 | 
				
			||||||
 | 
					import org.acejump.input.JumpMode
 | 
				
			||||||
 | 
					import org.acejump.search.Pattern.ALL_WORDS
 | 
				
			||||||
 | 
					import org.acejump.session.AceJumpListener
 | 
				
			||||||
 | 
					import org.acejump.session.SessionManager
 | 
				
			||||||
 | 
					import org.acejump.test.util.BaseTest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Test [org.acejump.ExternalUsage] endpoints.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ExternalUsageTest: BaseTest() {
 | 
				
			||||||
 | 
					  fun `test externally tagged results and listener notification`() {
 | 
				
			||||||
 | 
					    makeEditor("test externally tagged results")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SessionManager.start(myFixture.editor).markResults(sortedSetOf(4, 10, 15))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TestCase.assertEquals(3, session.tags.size)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var shouldBeTrueAfterFinished = false
 | 
				
			||||||
 | 
					    session.addAceJumpListener(object: AceJumpListener {
 | 
				
			||||||
 | 
					      override fun finished(mark: String?, query: String?) {
 | 
				
			||||||
 | 
					        shouldBeTrueAfterFinished = true
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    typeAndWaitForResults(session.tags[0].key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TestCase.assertTrue(shouldBeTrueAfterFinished)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  fun `test externally tagged results with multiple editors`() {
 | 
				
			||||||
 | 
					    val fileA = MockVirtualFile("a.txt", "first file")
 | 
				
			||||||
 | 
					    val fileB = MockVirtualFile("b.txt", "second file with more markers")
 | 
				
			||||||
 | 
					    myManager.openFile(fileA, true)
 | 
				
			||||||
 | 
					    myManager.openFile(fileB, false)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    val mainEditor = (myManager.selectedEditor as TextEditor).editor
 | 
				
			||||||
 | 
					    val editorA = (myManager.getEditors(fileA).single() as TextEditor).editor
 | 
				
			||||||
 | 
					    val editorB = (myManager.getEditors(fileB).single() as TextEditor).editor
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    val session = SessionManager.start(mainEditor, listOf(editorA, editorB))
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    session.markResults(mapOf(
 | 
				
			||||||
 | 
					      editorA to IntArrayList(intArrayOf(0, 6)),
 | 
				
			||||||
 | 
					      editorB to IntArrayList(intArrayOf(0, 7, 22))
 | 
				
			||||||
 | 
					    ))
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					    TestCase.assertEquals(5, session.tags.size)
 | 
				
			||||||
 | 
					    TestCase.assertEquals(2, session.tags.count { it.value.editor === editorA })
 | 
				
			||||||
 | 
					    TestCase.assertEquals(3, session.tags.count { it.value.editor === editorB })
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    TestCase.assertEquals(listOf(0, 6), session.tags
 | 
				
			||||||
 | 
					      .filter { it.value.editor === editorA }
 | 
				
			||||||
 | 
					      .map { it.value.offset }
 | 
				
			||||||
 | 
					      .sorted())
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    TestCase.assertEquals(listOf(0, 7, 22), session.tags
 | 
				
			||||||
 | 
					      .filter { it.value.editor === editorB }
 | 
				
			||||||
 | 
					      .map { it.value.offset }
 | 
				
			||||||
 | 
					      .sorted())
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun `test external pattern usage`() {
 | 
				
			||||||
 | 
					    makeEditor("test external pattern usage")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SessionManager.start(myFixture.editor)
 | 
				
			||||||
 | 
					      .startRegexSearch(ALL_WORDS, WHOLE_FILE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TestCase.assertEquals(4, session.tags.size)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun `test external regex usage`() {
 | 
				
			||||||
 | 
					    makeEditor("test external regex usage")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SessionManager.start(myFixture.editor)
 | 
				
			||||||
 | 
					      .startRegexSearch("[aeiou]+", WHOLE_FILE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TestCase.assertEquals(8, session.tags.size)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun `test external jump with bounds`() {
 | 
				
			||||||
 | 
					    makeEditor("test word and word usage")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SessionManager.start(myFixture.editor)
 | 
				
			||||||
 | 
					      .toggleJumpMode(JumpMode.JUMP, object : Boundaries {
 | 
				
			||||||
 | 
					        override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
 | 
				
			||||||
 | 
					          return 14..18
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
 | 
				
			||||||
 | 
					          return offset in 14..18
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    typeAndWaitForResults("word")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TestCase.assertEquals(1, session.tags.size)
 | 
				
			||||||
 | 
					    TestCase.assertEquals(14, session.tags.single().value.offset)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun `test listener query and mark`() {
 | 
				
			||||||
 | 
					    "<caret>testing 1234".search("g")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var detectedMark: String? = null
 | 
				
			||||||
 | 
					    var detectedQuery: String? = null
 | 
				
			||||||
 | 
					    session.addAceJumpListener(object: AceJumpListener {
 | 
				
			||||||
 | 
					      override fun finished(mark: String?, query: String?) {
 | 
				
			||||||
 | 
					        detectedMark = mark
 | 
				
			||||||
 | 
					        detectedQuery = query
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val mark = session.tags[0].key
 | 
				
			||||||
 | 
					    typeAndWaitForResults(mark)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TestCase.assertEquals(mark, detectedMark)
 | 
				
			||||||
 | 
					    TestCase.assertEquals("g", detectedQuery)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun `test listener after escape`() {
 | 
				
			||||||
 | 
					    "<caret>testing 1234".search("g")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var detectedMark: String? = null
 | 
				
			||||||
 | 
					    var detectedQuery: String? = null
 | 
				
			||||||
 | 
					    session.addAceJumpListener(object: AceJumpListener {
 | 
				
			||||||
 | 
					      override fun finished(mark: String?, query: String?) {
 | 
				
			||||||
 | 
					        detectedMark = mark
 | 
				
			||||||
 | 
					        detectedQuery = query
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    myFixture.performEditorAction("EditorEscape")
 | 
				
			||||||
 | 
					    UIUtil.dispatchAllInvocationEvents()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TestCase.assertEquals(null, detectedMark)
 | 
				
			||||||
 | 
					    TestCase.assertEquals(null, detectedQuery)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun `test listener for word motion`() {
 | 
				
			||||||
 | 
					    makeEditor("test word action")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    takeAction(AceAction.StartAllWordsMode())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var detectedMark: String? = null
 | 
				
			||||||
 | 
					    var detectedQuery: String? = null
 | 
				
			||||||
 | 
					    session.addAceJumpListener(object: AceJumpListener {
 | 
				
			||||||
 | 
					      override fun finished(mark: String?, query: String?) {
 | 
				
			||||||
 | 
					        detectedMark = mark
 | 
				
			||||||
 | 
					        detectedQuery = query
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val mark = session.tags[1].key
 | 
				
			||||||
 | 
					    typeAndWaitForResults(mark)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TestCase.assertEquals(mark, detectedMark)
 | 
				
			||||||
 | 
					    TestCase.assertEquals("", detectedQuery)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -6,27 +6,27 @@ import kotlin.random.Random
 | 
				
			|||||||
import kotlin.system.measureTimeMillis
 | 
					import kotlin.system.measureTimeMillis
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Ignore
 | 
					@Ignore
 | 
				
			||||||
class LatencyTest : BaseTest() {
 | 
					class LatencyTest: BaseTest() {
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private fun `test tag latency`(editorText: String) {
 | 
					  private fun `test tag latency`(editorText: String) {
 | 
				
			||||||
    val chars = editorText.toCharArray().distinct().filter { !it.isWhitespace() }
 | 
					    val chars = editorText.toCharArray().distinct().filter { !it.isWhitespace() }
 | 
				
			||||||
    val avg = averageTimeWithWarmup(warmupRuns = 10, timedRuns = 10) {
 | 
					    val avg = averageTimeWithWarmup(warmupRuns = 10, timedRuns = 10) {
 | 
				
			||||||
      var time = 0L
 | 
					      var time = 0L
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      for (query in chars) {
 | 
					      for (query in chars) {
 | 
				
			||||||
        makeEditor(editorText)
 | 
					        makeEditor(editorText)
 | 
				
			||||||
        myFixture.testAction(AceAction.ActivateOrCycleMode)
 | 
					        myFixture.testAction(AceAction.ActivateOrCycleMode())
 | 
				
			||||||
        time += measureTimeMillis { typeAndWaitForResults("$query") }
 | 
					        time += measureTimeMillis { typeAndWaitForResults("$query") }
 | 
				
			||||||
        // TODO assert(Tagger.markers.isNotEmpty()) { "Should be tagged: $query" }
 | 
					        // TODO assert(Tagger.markers.isNotEmpty()) { "Should be tagged: $query" }
 | 
				
			||||||
        resetEditor()
 | 
					        resetEditor()
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      time
 | 
					      time
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    println("Average time to tag results: ${String.format("%.1f", avg.toDouble() / chars.size)} ms")
 | 
					    println("Average time to tag results: ${String.format("%.1f", avg.toDouble() / chars.size)} ms")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun `test random text latency`() = `test tag latency`(
 | 
					  fun `test random text latency`() = `test tag latency`(
 | 
				
			||||||
    generateSequence {
 | 
					    generateSequence {
 | 
				
			||||||
      generateSequence {
 | 
					      generateSequence {
 | 
				
			||||||
@@ -36,10 +36,8 @@ class LatencyTest : BaseTest() {
 | 
				
			|||||||
      }.take(20).joinToString(" ")
 | 
					      }.take(20).joinToString(" ")
 | 
				
			||||||
    }.take(100).joinToString("\n")
 | 
					    }.take(100).joinToString("\n")
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun `test lorem ipsum latency`() = `test tag latency`(
 | 
					  fun `test lorem ipsum latency`() = `test tag latency`(
 | 
				
			||||||
    File(
 | 
					    File(javaClass.classLoader.getResource("lipsum.txt")!!.file).readText()
 | 
				
			||||||
      javaClass.classLoader.getResource("lipsum.txt")!!.file
 | 
					 | 
				
			||||||
    ).readText()
 | 
					 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,72 +4,62 @@ import com.intellij.openapi.actionSystem.AnAction
 | 
				
			|||||||
import com.intellij.openapi.actionSystem.IdeActions
 | 
					import com.intellij.openapi.actionSystem.IdeActions
 | 
				
			||||||
import com.intellij.openapi.fileTypes.PlainTextFileType
 | 
					import com.intellij.openapi.fileTypes.PlainTextFileType
 | 
				
			||||||
import com.intellij.psi.PsiFile
 | 
					import com.intellij.psi.PsiFile
 | 
				
			||||||
import com.intellij.testFramework.fixtures.BasePlatformTestCase
 | 
					import com.intellij.testFramework.FileEditorManagerTestCase
 | 
				
			||||||
import com.intellij.util.ui.UIUtil
 | 
					import com.intellij.util.ui.UIUtil
 | 
				
			||||||
import org.acejump.action.AceAction
 | 
					import org.acejump.action.AceAction
 | 
				
			||||||
import org.acejump.session.SessionManager
 | 
					import org.acejump.session.SessionManager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
abstract class BaseTest : BasePlatformTestCase() {
 | 
					abstract class BaseTest: FileEditorManagerTestCase() {
 | 
				
			||||||
  companion object {
 | 
					  companion object {
 | 
				
			||||||
    inline fun averageTimeWithWarmup(warmupRuns: Int, timedRuns: Int, action: () -> Long): Long {
 | 
					    inline fun averageTimeWithWarmup(warmupRuns: Int, timedRuns: Int, action: () -> Long): Long {
 | 
				
			||||||
      repeat(warmupRuns) {
 | 
					      repeat(warmupRuns) { action() }
 | 
				
			||||||
        action()
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      var time = 0L
 | 
					      var time = 0L
 | 
				
			||||||
      
 | 
					      repeat(timedRuns) { time += action() }
 | 
				
			||||||
      repeat(timedRuns) {
 | 
					 | 
				
			||||||
        time += action()
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      return time / timedRuns
 | 
					      return time / timedRuns
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  protected val session
 | 
					  protected val session get() = SessionManager[myFixture.editor]!!
 | 
				
			||||||
    get() = SessionManager[myFixture.editor]!!
 | 
					
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  override fun tearDown() {
 | 
					  override fun tearDown() {
 | 
				
			||||||
    resetEditor()
 | 
					    resetEditor()
 | 
				
			||||||
    super.tearDown()
 | 
					    super.tearDown()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun takeAction(action: String) = myFixture.performEditorAction(action)
 | 
					  fun takeAction(action: String) = myFixture.performEditorAction(action)
 | 
				
			||||||
  fun takeAction(action: AnAction) = myFixture.testAction(action)
 | 
					  fun takeAction(action: AnAction) = myFixture.testAction(action)
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun makeEditor(contents: String): PsiFile {
 | 
					  fun makeEditor(contents: String): PsiFile =
 | 
				
			||||||
    return myFixture.configureByText(PlainTextFileType.INSTANCE, contents)
 | 
					    myFixture.configureByText(PlainTextFileType.INSTANCE, contents)
 | 
				
			||||||
  }
 | 
					
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  fun resetEditor() {
 | 
					  fun resetEditor() {
 | 
				
			||||||
    takeAction(IdeActions.ACTION_EDITOR_ESCAPE)
 | 
					    myFixture.editor?.let {
 | 
				
			||||||
    UIUtil.dispatchAllInvocationEvents()
 | 
					      takeAction(IdeActions.ACTION_EDITOR_ESCAPE)
 | 
				
			||||||
    assertEmpty(myFixture.editor.markupModel.allHighlighters)
 | 
					      UIUtil.dispatchAllInvocationEvents()
 | 
				
			||||||
 | 
					      assertEmpty(it.markupModel.allHighlighters)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    myManager.closeAllFiles()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun typeAndWaitForResults(string: String) {
 | 
					  fun typeAndWaitForResults(string: String) {
 | 
				
			||||||
    myFixture.type(string)
 | 
					    myFixture.type(string)
 | 
				
			||||||
    UIUtil.dispatchAllInvocationEvents()
 | 
					    UIUtil.dispatchAllInvocationEvents()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun String.executeQuery(query: String) {
 | 
					  fun String.executeQuery(query: String) = myFixture.run {
 | 
				
			||||||
    myFixture.run {
 | 
					    makeEditor(this@executeQuery)
 | 
				
			||||||
      makeEditor(this@executeQuery)
 | 
					    testAction(AceAction.ActivateOrCycleMode())
 | 
				
			||||||
      testAction(AceAction.ActivateOrCycleMode)
 | 
					    typeAndWaitForResults(query)
 | 
				
			||||||
      typeAndWaitForResults(query)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  fun String.search(query: String): Set<Int> {
 | 
					  fun String.search(query: String): Set<Int> {
 | 
				
			||||||
    this@search.executeQuery(query)
 | 
					    this@search.executeQuery(query)
 | 
				
			||||||
    this@search.replace(Regex("<[^>]*>"), "").assertCorrectNumberOfTags(query)
 | 
					    this@search.replace(Regex("<[^>]*>"), "").assertCorrectNumberOfTags(query)
 | 
				
			||||||
    return myFixture.editor.markupModel.allHighlighters.map { it.startOffset }.toSet()
 | 
					    return myFixture.editor.markupModel.allHighlighters.map { it.startOffset }.toSet()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  private fun String.assertCorrectNumberOfTags(query: String) {
 | 
					  private fun String.assertCorrectNumberOfTags(query: String) =
 | 
				
			||||||
    assertEquals(split(query.fold("") { prefix, char ->
 | 
					    assertEquals(split(query.fold("") { prefix, char ->
 | 
				
			||||||
      if ((prefix + char) in this) prefix + char else return
 | 
					      if ((prefix + char) in this) prefix + char else return
 | 
				
			||||||
    }).size - 1, myFixture.editor.markupModel.allHighlighters.size)
 | 
					    }).size - 1, myFixture.editor.markupModel.allHighlighters.size)
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user