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
Applying code tags to just a single word or phrase in a sentence #552
Comments
I agree that inline code formatting would be nice. I've wanted it too!
Just to clarify, Trix has two kinds of formatting attributes: text (inline) and block. The first group of toolbar buttons apply text formatting, and the second group applies block formatting. For the most part, the buttons in each group behave the same. Following those guidelines, inline code formatting would need to be implemented as a text attribute, and would need its own toolbar button in the first group. That's kind of clunky though since there'd be two code formatting buttons. Ideally, one button would just do the right thing, like you said. I took a shot at implementing that as a plugin of sorts using Trix's events and editor API: Trix.config.textAttributes.inlineCode = {
tagName: "code",
inheritable: true
}
addEventListener("trix-initialize", event => {
const element = event.target
const { toolbarElement, editor } = element
const blockCodeButton = toolbarElement.querySelector("[data-trix-attribute=code]")
const inlineCodeButton = blockCodeButton.cloneNode(true)
inlineCodeButton.hidden = true
inlineCodeButton.dataset.trixAttribute = "inlineCode"
blockCodeButton.insertAdjacentElement("afterend", inlineCodeButton)
element.addEventListener("trix-selection-change", _ => {
const type = getCodeFormattingType()
blockCodeButton.hidden = type == "inline"
inlineCodeButton.hidden = type == "block"
})
function getCodeFormattingType() {
if (editor.attributeIsActive("code")) return "block"
if (editor.attributeIsActive("inlineCode")) return "inline"
const range = editor.getSelectedRange()
if (range[0] == range[1]) return "block"
const text = editor.getSelectedDocument().toString().trim()
return /\n/.test(text) ? "block" : "inline"
}
}) |
Hey, thanks a lot for supplying that plugin snippet for now. That works quite nicely for the time being. Are you going to leave this open until you decide how to deal with having a single button for both a block and inline effect? |
I'm going to close this since it's technically not a bug. Trix doesn't provide inline code formatting out of the box, and block code formatting is working as designed. Thanks for bringing this up though! I'd like to add contextual single-button formatting in a future update. |
Sorry for hijacking an existing issue. Is inline code formatting something the team would accept a pull request for? Also (a first timer here), how would this work in regards to Basecamp? If such a pull request was ever accepted, would the new feature be also added to Basecamp itself? Thanks! |
It generally seems to me that (regardless of trix's feature-set) given that Basecamp powers a lot of software companies, I'd love to see it in Basecamp :) |
@javan are you going to accept PR on this? |
Just want to throw in some more support for this idea. Our team is doing substantially fewer conversations on Basecamp message board due to this missing backtick feature, instead preferring environments like Slack, even though Basecamp would be the better place for persistent discussions. |
So any reason this minor change that seems to be fully working doesn't get merged in after 3 years? Seems kinda silly considering a ton of people have shown interest. Also how do technical people at Basecamp not find it irritating that they can't do this? Like every other place supports this. |
FWIW as a Basecamp user I would find this super-helpful! 🙏 |
Agree. |
Agree, please 🙏 |
Very useful for me also 🙏 |
Has anyone made a PR for this / fork / gem? |
Just adding support for this being a native feature of Trix 👍 |
Very disappointed to see that such a basic thing like inline code formatting is still not supported, even Markdown supports it 👀 |
I don't think there's anything fundamental in the philosophy of this project that would prevent the addition of this feature. I think it's a combination of the following things:
|
Sure, but I use Basecamp desktop for Mac, where I'd like this feature. I do not know how to include this plugin snippet in the app, or if that's even possible. Is it? |
I believe the workaround is for folks whose apps use Trix — I imagine the middle two points:
Bare the biggest weight with regard to this being a feature of Basecamp's implementation of Trix. At the end of the day adding this feature to Trix and having the functionality in Basecamp are separate things. |
You are both right @jhollowed & @jon-sully. I was referring to folks that use Trix in their apps. However, if this makes it into Trix here, it will eventually make it into Basecamp (I hope) 😄. |
Until Basecamp decides to support inline code styling, a workaround is to use the plugin implementation that @javan suggested here via a userscript manager (like Violentmonkey, Tampermonkey, or Greasemonkey). Here's a gist of the userscript I'm using. It's essentially what @javan posted above with some modifications to add the The obvious downside is that everyone needs to have this userscript enabled to see the effect. I'm really hoping Basecamp implements inline code styling at some point in the near future. |
When selecting just a word or phrase and pressing the
< >
button, the entire sentence gets displayed as a code block.Steps to Reproduce
< >
button.Details
Expected Results
I would have expected an inline
<code>open-source</code>
block to be used just like the GitHub markdown editor allows you to do. In Trix terms, I would have expected the behavior to match the bold button.Proposed Fix (in theory)
If text is selected, apply code tag to selected text, else apply code tag to full sentence.
The text was updated successfully, but these errors were encountered: