Skip to content
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

Display number of instances found on find status label #685

Closed
CetoBasilius opened this issue Aug 15, 2016 · 7 comments
Closed

Display number of instances found on find status label #685

CetoBasilius opened this issue Aug 15, 2016 · 7 comments
Assignees

Comments

@CetoBasilius
Copy link

When searching for a text, the only status displayed is when the search reaches the end of text and wraps around. As an enhancement, it would be nice to see how many results were found, if possible.

This would be helpful in some cases where we need to check how many times a function gets called or how many times a certain string is being used in some data structures.

calling the SetStatus function i was able to make a mock of the feature, something like this:
screen shot 2016-08-15 at 12 50 21 pm

@pkulchenko
Copy link
Owner

I considered this, but it complicates the search and makes the results less predictable (performance-wise) on large documents as it either needs to count instances on the first (each?) search or to do it in the background and then present the result. While I agree it's convenient to have, either options doesn't really sound appealing to me.

When the user selects multiple instances, the number of instances is shown in the status bar: Sel: <total-size>/<number-of-instances>.

What I can probably do is to keep track of visited instances and when a full loop is complete, show the number of instances (since all of them should be visited).

@CetoBasilius
Copy link
Author

That should work as well

@pkulchenko pkulchenko self-assigned this Aug 27, 2016
@CetoBasilius
Copy link
Author

@pkulchenko Today i remembered, i am using the highlightselected plugin, maybe this feature could be implemented on the plugin instead, since it searches for all instances itself?

@pkulchenko
Copy link
Owner

@CetoBasilius, try this patch to highlightselected:

diff --git a/highlightselected.lua b/highlightselected.lua
index 76cce40..0ad4005 100644
--- a/highlightselected.lua
+++ b/highlightselected.lua
@@ -6,7 +6,7 @@ return {
   name = "Highlight selected",
   description = "Highlights all instances of a selected word.",
   author = "Paul Kulchenko",
-  version = 0.16,
+  version = 0.17,
   dependencies = "1.11",

   onRegister = function() ide:AddIndicator(indicname) end,
@@ -52,7 +52,7 @@ return {
     local flags = editor:GetSearchFlags()
     editor:SetSearchFlags(wxstc.wxSTC_FIND_WHOLEWORD + wxstc.wxSTC_FIND_MATCHCASE)

-    local pos = 0
+    local pos, num = 0, 0
     while true do
       editor:SetTargetStart(pos)
       editor:SetTargetEnd(length)
@@ -61,7 +61,9 @@ return {

       editor:IndicatorFillRange(pos, #value)
       pos = pos + #value
+      num = num + 1
     end
+    ide:SetStatusFor(("Found %d instance(s)."):format(num), 5)
     editor:SetSearchFlags(flags)
   end,
 }

@CetoBasilius
Copy link
Author

Yes! that works great! Any plans on pushing to the main packages repository?

@pkulchenko
Copy link
Owner

Yes, will do shortly.

@CetoBasilius
Copy link
Author

Perfect. Thank you very much, @pkulchenko keep up the great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants