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

Implement cursor moving and editing with arrow keys in the textarea widget. #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

golbin
Copy link

@golbin golbin commented Jul 18, 2015

Now, users can move with arrow keys and edit text anywhere on a cursor. And it works well with multi-byte characters but there is a little bug.

And actually It has a performance problem when you copy a large text and if we want fix this, fix "element.parseContent" function.

But I think, it's enough for editing small text and if someone want to edit large text, it's better to use slap-editor.

@chjj
Copy link
Owner

chjj commented Jul 18, 2015

But I think, it's enough for editing small text and if someone want to edit large text, it's better to use slap-editor.

That's okay, we want a small editor in blessed. So this would be perfect.

@dbkaplun, what do you think?

@dbkaplun
Copy link
Collaborator

Hey,

I completely agree that blessed could use some improved text editing. I took a look a cursory look at this patch and it has some bugs:

  • Tabs don't work right
  • Delete doesn't work right when the cursor is at the beginning of the document
  • Maybe this should go into Input? Theoretically speaking

Good job @golbin!

@chjj
Copy link
Owner

chjj commented Jul 18, 2015

@dbkaplun, yes those first two bugs should be fixed, but I don't think it should go into Input. Anything can be an input (e.g. a Button). It doesn't need cursor movements.

This also needs to be refactored a little bit to match coding style. edit: Actually taking a second look, it's pretty good in that regard, just concatenation or addition always uses the operator at the beginning of the line when line feed separated: a \n+ b instead of a +\n b. Double-quotes are a no-no.

@chjj
Copy link
Owner

chjj commented Jul 18, 2015

@golbin, have you tested this with all manner of fullUnicode characters? double-width, double-width surrogates, surrogates, and combining chars? That would be the trickiest part. I don't think I ever had it perfect. If you got that working it would be fantastic.

@golbin
Copy link
Author

golbin commented Jul 18, 2015

@chjj I've test surrogate and combining functions but it did't works well. So, I just check character width and it works almost cases for CJK. There is a known bug which is during character is combining.

@chjj
Copy link
Owner

chjj commented Jul 19, 2015

@golbin, @dbkaplun, I think you two should work together on a concensus minimal text editor for Textarea. @dbkaplun has the most experience with editing and @golbin dealt with all the unicode gotchas and made text navigation of his own.

If @dbkaplun rips some of his text navigation code and @golbin adds the unicode/double-width/surrogate/combining/fuck-unicode/etc stuff, I think you guys would make something good.

Would you guys work together on this?

@chjj
Copy link
Owner

chjj commented Jul 19, 2015

Or maybe @dbkaplun could add a stripped down verson of his Editor element and @golbin adds the unicode stuff?

@golbin
Copy link
Author

golbin commented Jul 19, 2015

I'm OK both way. 😄

@KalenAnson
Copy link

Would love to have this functionality in textboxes as well so a user can edit a line of text using cursor movements (left and right only though).

@dbkaplun
Copy link
Collaborator

Hey, I've been meaning to mention, I've factored out the editor widget from slap here. It features navigation via configurable keybindings as well as mouse support. Hope it's useful!

@KalenAnson
Copy link

@dbkaplun This may be exactly what I need. Thanks!

@j-em
Copy link

j-em commented Apr 20, 2016

Is this PR still active or the recommended way to get arrow support in textarea is now editor-widget ?

@skerit
Copy link

skerit commented Oct 14, 2016

I was planning on using this custom Textarea because editor-widget just pulls in way too many dependencies when you only want some arrow navigation and such.

So I tried using this, but the cursor ends up in the totally wrong place and characters get... scrambled, somehow, while typing.

I looked at the code and found that this was the issue, in _applyCursor:

var cyMax = lpos.yl - lpos.yi + this.iheight;

this.iheight was always 0 for some reason, so the cursor ended up at the top of the screen.
Just changing it to

var cyMax = lpos.yl;

fixed that issue for me. I don't know if it's because I positioned the widget using bottom: 0 or not, but anyway.

@oaknuggins
Copy link

Hello @golbin and @skerit,

I found your patches to be very useful. Is it OK if these patches were to be applied on a new "blessed" fork? The rest of the repo would be kept the same.

Thanks a lot!

@golbin
Copy link
Author

golbin commented Feb 18, 2018

@oaknuggins I think it works with latest blessed. But it's a little buggy.

@antonmedv
Copy link

Awesome work @golbin
Did anyone working on something more powerful but lightweight (not slap's editor-widget)?

@yyjjqq94
Copy link

yyjjqq94 commented Aug 4, 2020

@golbin good work. why lastest blessed desn't merge this pr? no progress on this problem?

@antonmedv
Copy link

Blessed is dead for years now. I’m thinking to creating new one from scratch, if I find some time.

@hp4k1h5
Copy link

hp4k1h5 commented Aug 15, 2020

Blessed is dead for years now. I’m thinking to creating new one from scratch, if I find some time.

id be happy to contribute if you do start something new.

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.