zefyr icon indicating copy to clipboard operation
zefyr copied to clipboard

Hyperlink cannot be triggered in non edit state.

Open hetian9288 opened this issue 6 years ago • 12 comments

1、Hyperlink cannot be triggered in non edit state. 2、EditableBox will terminate the GestureDetector event of custom widgets.

hetian9288 avatar Nov 01 '18 16:11 hetian9288

Thanks for submitting this issue! This is definitely something I'll be looking to fix.

pulyaevskiy avatar Nov 02 '18 17:11 pulyaevskiy

Is this fixed?

abinmittu avatar Jan 05 '19 23:01 abinmittu

I’m planning to address this in the next couple of weeks, so stay tuned!

pulyaevskiy avatar Jan 06 '19 00:01 pulyaevskiy

Any updates on this??

kdcyberdude avatar Nov 28 '19 09:11 kdcyberdude

I'll have a look next week. I also have the issue.

cgestes avatar Nov 28 '19 14:11 cgestes

a solution here: https://github.com/memspace/zefyr/pull/211

:)

cgestes avatar Nov 28 '19 15:11 cgestes

You can listen to controller and then get the style attribute of the clicked element if thats notusattribte.Link. you got the url just open it with url_launcher

raj457036 avatar Mar 18 '20 07:03 raj457036

1、Hyperlink cannot be triggered in non edit state. 2、EditableBox will terminate the GestureDetector event of custom widgets.

You can use TextSelectionGestureDetector but there is a better way to handle ur need. Check my above comment

raj457036 avatar Mar 18 '20 07:03 raj457036

You can listen to controller and then get the style attribute of the clicked element if thats notusattribte.Link. you got the url just open it with url_launcher

Can you please write some code to explain this a bit? How can I get the text on which the user tapped for checking if it is a link? I'm a little new to Flutter, so it'd be great if you could help.

jagjot26 avatar Mar 20 '20 16:03 jagjot26

This is probably not relevant to you guys anymore, but the links still didn't work for me in a non-edit state, so I found this solution based on raj457036 comment:

First, add a listener to the controller via controller.addListener(handleLinkClicked); This listener will get triggered everytime a user clicks inside the editor, even if it is on mode.view. You can check whether the clicked item is a link via:

void handleLinkClicked() {
  var styles = _controller.getSelectionStyle();
  for (var atr in styles.values) {
  if (atr.key == "a") print("here's the clicked link: " + atr.value);
  }
}

Jackilion avatar Aug 16 '20 20:08 Jackilion

You can listen to controller and then get the style attribute of the clicked element if thats notusattribte.Link. you got the url just open it with url_launcher

Can you please write some code to explain this a bit? How can I get the text on which the user tapped for checking if it is a link? I'm a little new to Flutter, so it'd be great if you could help.

first of all, apologies I was very busy with work

@Jackilion your solution might also work well.

So here is what I used in my project

...
// define controller and listen to controller
_controller = ZefyrController(
    NotusDocument.fromDelta(delta)
)..addListener(linkListener);

...

linkListener() {
    // check if any link is clicked
    final _url = _controller.getSelectionStyle().get(NotusAttribute.link)?.value;
   
    // if url found launch it
    if (_url != null) {
        launchURL(_url);
    }
}

raj457036 avatar Aug 16 '20 21:08 raj457036

Please see https://github.com/memspace/zefyr/pull/543

  • hittestchildren implementation allows child widget of Zefyr to implement their GestureDetector if they want
  • one of the patch allows clicking links no matter the mode of edition

I believe the current issue without #543 is reversed: cannot trigger links while editing :D

cgestes avatar Oct 20 '21 16:10 cgestes