Simon Lydell [Tue, 30 Jul 2013 22:00:21 +0000 (00:00 +0200)]
Enhance performance
Instead of sorting the whole array of elements in each iteration of the
huffman tree construction, we now search backwards for the first index
where the sum to insert is equal to or greater than the weight at that
index. Directly after that index the sum is inserted. According to some
tests I made, this is about 3 times faster than before.
Simon Lydell [Tue, 30 Jul 2013 12:47:26 +0000 (14:47 +0200)]
Group all hint injection code in hints.coffee
Before, the hint/marker injection code was spread out in both hints.coffee
and marker.coffee. Creation and injection of markers does not really
belong to the Marker class. It is just a wrapper around a single markable
element.
Now, all hint/marker creation and injection is done in hints.coffee. This
has several benefits: The code is a lot easier to understand, and the
number of loops over arrays of markers could be reduced a lot, enhancing
performance.
I've also cleaned the code up, as well as removed code that was totally
useless: Before, `element.getClientRects()` was scanned for rectangles
matching the `isRectOk()` test. However, none of them could ever pass,
since `isRectOk()` looks for width and height properties on the
rectangles, which do not even exist (however, they do on the rectangle
returned by `element.getBoundingClientRect()`). This also fixes the uncaught
ReferenceErrors complaining about undefined width and height properties.
This also removed unnecessary loops, which enhances performance even more.
Some of these changes could have been made outside the huffman branch, I
realize now. However, it would take some work, and I'm not sure it is
worth it.
An improvement I noticed with this patch: It is now possible to click the
green, hidden until hover install buttons on AMO:
https://addons.mozilla.org/firefox/addon/VimFx/versions/
Simon Lydell [Tue, 30 Jul 2013 09:44:56 +0000 (11:44 +0200)]
Refactor to clarify and enhance performance
The code should be easier to understand now, and has a more flexible API.
Thanks to the latter, we now get better performance. Before, we had to
iterate the whole array of markers generated by `injectHints` both before
and after `addHuffmanCodeWordsTo`. Now, that is not necessary anymore.
Simon Lydell [Mon, 29 Jul 2013 21:19:00 +0000 (23:19 +0200)]
Change `markers?.length` into `markers.length`
The existence check is no longer needed, since `injectHints` now always
returns an array: Where it before returned `undefined`, it now returns an
empty array.
Simon Lydell [Mon, 29 Jul 2013 18:27:31 +0000 (20:27 +0200)]
Fix typo
Line 64 in marker.coffee contains a reference to `@markedElement`, though
that is the only occurance in the entire files. It clearly looks like it
is a typo of `@markerElement`, by inspecting the nearby code. The odd
thing, though, is that that line seems to have been added by commit b5f488df, and already there the typo exists. Has the code ever worked?
I'm not sure if this fix currently fixes any issues, but it is needed in
the Huffman branch in order not to throw errors.
Simon Lydell [Mon, 29 Jul 2013 18:14:53 +0000 (20:14 +0200)]
Fix `injectHints` might return undefined markers
The `inner` function of `injectHints` now returns an empty array instead
of undefined if no markers could be produced, since all results of the
`inner` function are recursively concatenated. VimFx seems to have worked
well even though some entries in the array of markers returned by
`injectHints` could be undefined. However, on the Huffman branch, the
undefined entries sometimes caused a TypeError to be thrown, which
eventually resulted in that none of the hint markers were given any hints.
Closes #114, closes #115.
Find will now start from current selection/last found match
Find string is now global for all windows
'gh' command will now function properly for urls without protocol part (http://)
Simon Lydell [Tue, 16 Jul 2013 19:04:41 +0000 (21:04 +0200)]
Consistent use of parenthesis
Functions pretty much always use parenthesis, unless:
- The last argument is a function literal
- The function call is multiline for some (other) reason
- The specific case makes it less readable with parenthesis
- The function is `require`
Simon Lydell [Tue, 16 Jul 2013 16:17:15 +0000 (18:17 +0200)]
Remove chrome.coffee
- Remove chrome.coffee, which added Cc, Ci and Cu globally.
- Add definitions of those in files where needed.
- Fix consistent formatting of their definitions.
- Fix consistent placement of their definitions: after reqiures. Includes
cleaning up the requires sometimes, involving alignment.
- When fixing alignment of requires I couldn't help but to also fix
alignments in other places.
- Trailing whitespace was also removed by my editor.
Simon Lydell [Tue, 16 Jul 2013 14:35:00 +0000 (16:35 +0200)]
Fix frames handling
Every frame got the same hints as the others, basically. Now
`Marker.createMarkers()` does not give its markers any hints anymore.
Instead, all markers from all frames are collected in `injectHints()` and
then given markers. I am not sure how good/nice the solution is, but it
works.
Simon Lydell [Tue, 16 Jul 2013 09:31:50 +0000 (11:31 +0200)]
Use Huffman algorithm for hints generation (fix #112)
The Huffman algorithm is now used to generate optimal prefix codes for all
focusable elements. The area of each element is used as _weight_. The
higher the weight, the shorter the hint.
Note:
The old algorithm seemed to give shorter hints to `<a>` elements. That is
currently not the case with the new algorithm.
Other related changes:
- Change minimum allowed number of hint chars from 3 to 2, since the new
algorithm supports it.
- Change default hint chars, since with the new algorithm the best keys
should be at the beginning of the string.
- My editor is set to strip trailing white space. Apparently there was a
lot of trailing whitespace in many files, so a diff of this commit is a
bit messy.
Closes #111. Validating custom hint characters.
If there are less than 3 custom hint characters the the default hint characters are used.
Custom hint characters are filtered to remove duplicates.