Skip to content

Comments

Enhance the capabilities of ctrl-l and the goto action#2522

Open
xyproto wants to merge 1 commit intomicro-editor:masterfrom
xyproto:powergoto
Open

Enhance the capabilities of ctrl-l and the goto action#2522
xyproto wants to merge 1 commit intomicro-editor:masterfrom
xyproto:powergoto

Conversation

@xyproto
Copy link

@xyproto xyproto commented Aug 9, 2022

After pressing ctrl-l:

  • If at the top of the file and return is pressed, jump to the bottom.
  • If at anywhere else in the file and return is pressed, jump to the top.
  • Typing in a percentage (like 50%) jumps to the middle of the file.
  • Typing in a ratio (like .5 or 0.5) jumps to the middle of the file.

Ratios like 0,5 and ,5 are also supported, since some languages use a comma instead.

I've used this functionality almost daily for a couple of years with my little editor o, have become addicted to the workflow and wanted to share it, since I really appreciate the micro editor.

@xyproto xyproto force-pushed the powergoto branch 3 times, most recently from cc063d7 to 1f50d33 Compare August 9, 2022 15:56
@xyproto xyproto changed the title Make the goto action more powerful Enhance the capabilities of ctrl-l and the goto action Dec 15, 2022
After pressing ctrl-l:

* If at the bottom of the file and return is pressed, jump to the top.
* If at the top of the file and return is pressed, jump to the bottom.
* Typing in a percentage (like "50%") jumps to the center line.
* Typing in a ratio (like ".5" or "0.5") jumps to the center line.

Ratios like "0,5" and ",5" are also supported, since some languages
use a comma instead.
}
targetLocation := buffer.Loc{0, int(math.Round(float64(h.Buf.End().Y) * ratio))}
h.Cursor.Deselect(true)
h.Cursor.Loc = targetLocation
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please note that for goto (and generally for cases where the new location may be far away from the old location) you should use h.GotoLoc() rather than just set the new location and relocate. See #2628.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants