psugihara / FreeChat

llama.cpp based AI chat app for macOS
https://www.freechat.run
MIT License
425 stars 37 forks source link

Enable full text selection #65

Closed finallyblueskies closed 3 weeks ago

finallyblueskies commented 5 months ago

This pull request fixes text selection #22 by adding a button in the chat interface. You can see it here:

https://github.com/psugihara/FreeChat/assets/14274086/8b9d4727-62ab-4f55-9bb7-0de7700c360e

This allows users to select text more easily by removing Markdown rendering.

It makes sense to upgrade this feature to an "Edit message" capability.

Reasoning

Despite my efforts, I couldn't implement full text selection without disabling markdown. This pull request details my struggles, primarily focused on using WKWebView to display messages. Long story short:

vercel[bot] commented 5 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
free-chat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 18, 2024 3:16am
psugihara commented 5 months ago

All makes sense, thanks for all the research here. I agree with the conclusion that it's not worth it to render the whole scrollview with webviews even though that would offer the best text selection. It's weird that browser style text selection is so hard to achieve with SwiftUI but that seems to be the case.

I like this solution from the video but I wonder if it should go in the "..." menu. I'll play with it more tomorrow and have a think.

psugihara commented 5 months ago

Another quick thought. I wonder if there's a hybrid solution where each message renders its own wkwebview for the content (but not the buttons etc). You wouldn't be able to select across messages, but you wouldn't have to toggle on/off to achieve message within the selection and you'd get the richer markdown features you mention.

finallyblueskies commented 5 months ago

Another quick thought. I wonder if there's a hybrid solution where each message renders its own wkwebview for the content (but not the buttons etc). You wouldn't be able to select across messages, but you wouldn't have to toggle on/off to achieve message within the selection and you'd get the richer markdown features you mention.

I tried this and faced hurdles:

Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>

0x1280b39c0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'XPCConnectionTerminationWatchdog' for process with PID=76446, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}

....


These errors suggest that the processes for the WKWebViews were terminated or went missing because the system couldn't allocate the needed resources. No idea if this is workable, from what I've read WKWebViews are pretty resource intensive.

You can try a functional version of the hybrid approach you mention on [this commit](https://github.com/psugihara/FreeChat/pull/64/commits/d8202af930bb2f8c430e7d95d6b62ee2f22c6768).