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

Morgan/kill but reversable #2934

Merged

Conversation

morganrconnolly
Copy link
Contributor

adds hintmode excmd -K which restores killed elements in LIFO. -K for unKill
fixes #2794

Copy link
Member

@bovine3dom bovine3dom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks!

I replied to you on Matrix about the killStack but I'll reproduce it here:

> <@mci:matrix.org> Hello! I'm I'd like to work on this issue https://github.com/tridactyl/tridactyl/issues/2794 . Is content/state_content.ts the place to store the "killStack" ? 

Hi! Thanks for that PR. It looks good.
I wouldn't personally have put it there - we use it for stuff that needs to be shared between multiple scripts and particularly for state that other things need to be told about when there is a change. I would just do

"""
//#content_helper
const KILL_STACK = Element []
"""

above the hint function.
It doesn't really matter though : )

src/excmds.ts Outdated
@@ -4224,13 +4224,17 @@ export async function hint(option?: string, selectors?: string, ...rest: string[
selectHints = hinting.pipe_elements(
hinting.killables(),
elem => {
elem.remove()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably leave this in place and make a new "mode" for reversible deaths. The .remove part I think stops JavaScript from messing with an element so it probably would still be useful on particularly unruly sites.

return elem
},
rapid,
)
break

case "-K":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly uneasy about this being a hint mode. It sort of makes sense as it is related to the code above ... but it also doesn't as there are no hints to select. I think on balance it's probably OK.

@@ -9,6 +9,7 @@ Here are some of the most useful hint modes:
- `:hint -p` or `;p`: copy element text (such as a paragraph) to clipboard
- `:hint -#` or `;#`: copy anchor location. Useful for linking someone to a specific part of a page.
- `:hint -k` or `;k`: kill an element. Very satisfying.
- `:hint -K` or `;K`: restore killed elements in LIFO order. Fixes mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `:hint -K` or `;K`: restore killed elements in LIFO order. Fixes mistakes.
- `:hint -K` or `;K`: restore elements most recently killed via `:hint -k`. Fixes mistakes.

I think LIFO might not be understood by all our users. I also want to make sure it's clear that it they manually kill an element some other way this won't magically restore it : )

src/static/css/hint.css Outdated Show resolved Hide resolved
@morganrconnolly
Copy link
Contributor Author

@bovine3dom Thank you for the feedback! I'm much more fond of this PR now. I was able to implement all of your comments, but let me know if you see any other possible improvements. In particular, let me know if you think there are better names for the new reversible kill hint mode, now -K, and/or the command to restore killed elements , now :restorekill .

Copy link
Member

@bovine3dom bovine3dom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Just a few minor things and then the hard problem of picking a name. I'm happy to do all of them (at some point).

src/excmds.ts Outdated
- `bind ;c hint -c [class*="expand"],[class="togg"]` works particularly well on reddit and HN
- this works with most other hint modes, with the caveat that if other hint mode takes arguments your selector must contain no spaces, i.e. `hint -c[yourOtherFlag] [selector] [your other flag's arguments, which may contain spaces]`
- -f [text] hint links and inputs that display the given text
- -p copy an element's text to the clipboard -h select an element (as if you click-n-dragged over it) -P copy an element's title/alt text to the clipboard -r read an element's text with text-to-speech -i view an image -I view an image in a new tab -k delete an element from the page -K deletes an element from the page; deleted elements can be restored using :restorekilled. -s save (download) the linked resource -S save the linked image -a save-as the linked resource -A save-as the linked image -; focus an element and set it as the element or the child of the element to scroll -# yank an element's anchor URL to clipboard -c [selector] hint links that match the css selector `bind ;c hint -c [class*="expand"],[class="togg"]` works particularly well on reddit and HN this works with most other hint modes, with the caveat that if other hint mode takes arguments your selector must contain no spaces, i.e. `hint -c[yourOtherFlag] [selector] [your other flag's arguments, which may contain spaces]` -f [text] hint links and inputs that display the given text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like some formatting was lost here

@@ -20,13 +20,15 @@ export class PrevInput {
class ContentState {
mode: ModeName = "normal"
suffix = ""
killStack: Element[] = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need any of the changes to this file any more

src/excmds.ts Outdated
*NB: The most recently killed element that has not already been restored will be restored.
*/
//#content
export async function restorekill() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't know what to call this either. In general we have a convention of naming things [object][action], so under that this would be killrestore ... but I don't like that either : )

I'll try to think about it a bit more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about resurrect(), revive() or elementrestore()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like elementrestore the most out of those ... still not 100% happy with it though.

I'll try really hard to get round to look seriously at this PR next week : )

@bovine3dom bovine3dom self-assigned this Nov 3, 2020
@bovine3dom
Copy link
Member

LGTM - I'll merge once CI has passed. Thanks, and sorry it took so long to review :)

@bovine3dom bovine3dom merged commit 126a4e8 into tridactyl:master Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

;k but reversible
3 participants