MessageViewController icon indicating copy to clipboard operation
MessageViewController copied to clipboard

Interactively autoincrement list when commenting

Open viktorasl opened this issue 6 years ago • 12 comments

Hello! 👋 It's my first try to contribute to this amazing tool. To make it even more efficient to construct lists I've worked on interactive auto-increment (seen the request https://github.com/GitHawkApp/GitHawk/issues/1692).

Currently it does not do anything clever, just checks if a single new line text insertion occurs and then analyzes that text line. The work is done in textView(_:shouldChangeTextIn:replacementString:) which means that pasted text is ignored but that could be changed probably without much effort as the actual logic is decoupled.

In short what was done:

  • Observes changes made in text view and autoincrements both numbered and unordered lists if list constructon is detected.
  • Preserves text insertion text attributes
  • Sets correct text selection after autoincrement text is inserted

Next in feature polishing:

  • Preserve the indentation allowing same level list auto-increment

viktorasl avatar Mar 31 '18 20:03 viktorasl

@viktorasl Thanks for submitting this PR ❤️ I haven't dug into your code, but I think this functionality may be better targeted as an extension to GitHawk itself. But I could be wrong, just passing by 😇

SD10 avatar Mar 31 '18 21:03 SD10

Love this idea! But also agree it’d be better off in GitHawk itself because we shouldn’t have any actual features in this library.

Sent with GitHawk

rnystrom avatar Mar 31 '18 22:03 rnystrom

Oh, ok, I'll move the feature to GitHawk but not sure how I can implement there without modifying MessageViewController as I have to modify textView(_:shouldChangeTextIn:replacementString:) method. Any ideas how I can track what's being edited and where?

viktorasl avatar Apr 01 '18 06:04 viktorasl

@viktorasl IIRC there is an abstraction MessageTextViewListener that receives information from textView(_:shouldChangeTextIn:replacementString:). You just have to add your object conforming to this protocol to the array of listeners in the MessageTextView. We then iterate the array inside of the shouldChangeText delegate method.

SD10 avatar Apr 01 '18 06:04 SD10

Yeah, but the replacement string is not passed to the listeners

Sent with GitHawk

viktorasl avatar Apr 01 '18 07:04 viktorasl

@viktorasl You can submit an initial PR making it available? It’s useful information. I almost did this before when needing to fix a bug

Sent with GitHawk

SD10 avatar Apr 01 '18 07:04 SD10

Sorry for close and reopen, was testing GitHawk accessibility, accidently closed the issue.

Didn’t fully get the idea: shall I add the additional parameter in listeners metod to be able to pass replacement string in this repo?

Sent with GitHawk

viktorasl avatar Apr 01 '18 07:04 viktorasl

Yes @viktorasl that sounds 👌 to me

SD10 avatar Apr 01 '18 10:04 SD10

I faced some problems:

  • textView(_:shouldChangeTextIn:replacementString:) method has to return false if text was adjusted because it now adds actually typed new line where the cursor is placed. (e.g - A\n becomes not - A\n- but - A\n- \n).
  • Don't actually know how to workaround. I have an idea to change willChangeRange(textView: MessageTextView, to range: NSRange) so that it would return Bool and then textView(_:shouldChangeTextIn:replacementString:) result to false if at least one listener returns false. But it's quite fragile as generally result depends on a single listener response (if it's false).

Any ideas to solve those issues? I'm quite stuck not finding the balanced solution.

viktorasl avatar Apr 01 '18 12:04 viktorasl

More to that: willChangeRange(textView: MessageTextView, to range: NSRange) won't reflect actual change range if text is adjusted. Hmm, well this is a tricky one.

viktorasl avatar Apr 01 '18 12:04 viktorasl

Hey, long time no see! Can I do something to push this feature or should this just be closed?

viktorasl avatar Jan 15 '19 13:01 viktorasl

cc @rnystrom

BasThomas avatar Jan 16 '19 06:01 BasThomas