-
Notifications
You must be signed in to change notification settings - Fork 755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VIM-1970 | Working solution of plugin vim-highlightedyank #245
Conversation
Wow, you're right on time! A few days ago I've looked at this ticket and thought that it would be nice to have this feature in one of the next releases. Don't hesitate to reach me out in case of questions. Another great plugin is on the way and this is awesome! |
…o dynamically set highlight duration
Hey @AlexPl292 !
fun `test highlighting for a correct default amount of time`() {
doTest("yiw", code, code, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
Thread.sleep(100)
assertAllHighlightersCount(1)
Thread.sleep(300) // even value like 10000 does not work
assertAllHighlightersCount(0) //says that there is still 1 highlighter
}
fun `test highlighting for a correct user provided amount of time`() {
configureByJavaText(code)
typeText(StringHelper.parseKeys(":let g:highlightedyank_highlight_duration = \"500\"<CR>"))
typeText(StringHelper.parseKeys("yiw"))
Thread.sleep(100)
assertAllHighlightersCount(1)
Thread.sleep(200)
assertAllHighlightersCount(1)
Thread.sleep(200)
assertAllHighlightersCount(0)
} Do you have any thoughts on it? If you have any comments or ideas please let me know :) |
Hey! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, this is nice work, I like it! I've added some comments, could you please check them?
Regarding tests:
Check out TestHelper.kt
file with functions waitAndAssert
and assertDoesntChange
. I think you can test it using these functions. However, waitAndAssert
function runs an assertion in a loop for timeInMillis
milliseconds, what might be not really what we need. We can use assertDoesntChange
for, let's say, 290ms to check that highlighting isn't removed for this time, and waitAndAssert
for 20 ms to check that highlighting is removed in this time range.
You can even create your helper function that would check that something has happened at some moment.
Something like fun assertHappend(afterMillis: Int, precision: Int, assert: () -> Boolean)
And call it with assertHappend(300, 10) { /* Check highlighting is removed */ }
src/com/maddyhome/idea/vim/extension/highlightedyank/VimHighlightedYank.kt
Outdated
Show resolved
Hide resolved
src/com/maddyhome/idea/vim/extension/highlightedyank/VimHighlightedYank.kt
Outdated
Show resolved
Hide resolved
} | ||
|
||
private class HighlightHandler { | ||
private val yankHighlighters: MutableSet<Pair<Editor, RangeHighlighter>> = mutableSetOf() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any cases with more that one highlighter? If not, I suggest just store one current highlighter in the fields:
private var highlighter: RangeHighligher? = null
private var editor: Editor? = null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm creating multiple highlighters when user is in multi cursor mode. I haven't found the way to create highlighter with multiple ranges so I'm creating multiple highlighters
On the other hand I don't need editor for every highlighter, I just need one, so I've removed editor from set
src/com/maddyhome/idea/vim/extension/highlightedyank/VimHighlightedYank.kt
Outdated
Show resolved
Hide resolved
src/com/maddyhome/idea/vim/extension/highlightedyank/VimHighlightedYank.kt
Show resolved
Hide resolved
test/org/jetbrains/plugins/ideavim/extension/highlightedyank/VimHighlightedYankTest.kt
Show resolved
Hide resolved
@kamolsrisan Hi! I understand that you like the results and want it to be merged, but could you please stop posting this message? This already looks like spam. |
test/org/jetbrains/plugins/ideavim/extension/highlightedyank/VimHighlightedYankTest.kt
Show resolved
Hide resolved
Hey, I've added a commit with some small changes to speed up the process. Actually, I've just added insert listener and performed some small refactorings. Thank you very much for the contribution. This is great stuff, nice to see it in IdeaVim! |
I'm glad that I could add something to this really great project. Thanks |
I discovered highlightedyank through this PR, and it's now a firm favourite extension in both IdeaVim and my standard Vim config. Great PR! 🎉 |
Hey!
Before i go in I'd like to mention, that I've never contributed to any project before so if i did something wrong things please let me know :)
So, I've found issue (VIM-1970) on plugin that is really simple but makes vim a little bit more pleasurable. This is vim-highlightedyank. I've been using it with Vim and it would be nice to have it in ideavim.
There was no response since that question and I decided to implement it myself.
Based on your advice (
or create a draft PR to indicate that you've started working
) I've created a draft PR to let you know that I've started working on this.Right now I believe this draft is overall working version of the plugin. I was thinking if you have any thoughts on this solution.
It's still a draft and the next steps I would like to take are:
set vim-highlightedyank
let g:highlightedyank_highlight_duration = 1000
)What do you think about it?