-
Notifications
You must be signed in to change notification settings - Fork 8
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
Indentation in non-HTML documents #91
Comments
Even with HTML, it's waaaay too pushy with doing indentation its own, bizarre way. You have to select and delete these tabs manually, or use left arrow and then delete, because just pressing backspace deletes all the indents and the preceding line break. I wish there was a setting to disable automatic indentation altogether, because in its current form it's actively unhelpful and frustrating in 95% of the cases. |
For anyone still having this issue, here's a build of the plugin which does no indenting except where the templated language indicates it should indent. |
@Martmists-GH Are you able to share the code change required here? I'd be happy to provide a PR for this. |
EDIT: Decided to rewrite with an attempt at making indents work properly; If you need the version without indents, use the bottom snippet. I'll make a PR for this later today. <removed for being bad code, rewriting...> I think a PR would not work as it completely disables all pebble indents and only uses those from the data language, but here you go: // File: src/main/kotlin/com/github/bjansen/intellij/pebble/formatting/PebbleFormattingModelBuilder.kt
class PebbleBlock(
node: ASTNode,
wrap: Wrap?,
alignment: Alignment?,
settings: CodeStyleSettings,
blockFactory: TemplateLanguageBlockFactory,
foreignChildren: MutableList<DataLanguageBlockWrapper>?
) : TemplateLanguageBlock(node, wrap, alignment, blockFactory, settings, foreignChildren) {
override fun getTemplateTextElementType() = tokens[PebbleLexer.CONTENT]
override fun getIndent(): Indent? {
// ignore whitespace
if (myNode.text.trim().isEmpty()) {
return Indent.getNoneIndent()
}
val parent = parent
if (parent is DataLanguageBlockWrapper) {
return Indent.getNoneIndent() // Modified
} else if (parent is PebbleBlock) {
if (parent.node.lastChildNode == node) {
// we're the parent's end tag, don't indent
return Indent.getNoneIndent()
}
for (subBlock in parent.subBlocks) {
if (subBlock is DataLanguageBlockWrapper && subBlock.textRange.startOffset < textRange.startOffset) {
// We're next to a data language block, so we use its indent
return subBlock.indent
}
}
if (node.psi is PebbleTagDirective) {
// we're an opening tag, indent
return Indent.getNoneIndent() // Modified
}
}
return Indent.getNoneIndent()
}
override fun getChildIndent(): Indent? {
return Indent.getNoneIndent() // Modified
}
} |
Ah, thank you so much @Martmists-GH! |
I installed @Martmists-GH's version and it's just so. much. better. It's so satisfying to not be frustrated. For something pull-request-worthy I'd suggest adding a checkbox that selects between old and new behavior to this settings UI the plugin already has: |
@Martmists-GH thanks for the PR, I'm reviewing it! |
I'm currently working on a project that makes use of a custom SSG (static site generator) to generate a website from Markdown and HTML files, all of which may be Pebble templates. When the directory containing the site's sources is set up via IJ's template language settings as containing Markdown-formatted Pebble templates, and the files end in
.md.peb
, the way indentation is handled in the files is… strange, to say the least.As an example, in a document with no Pebble syntax whatsoever, let's create a partial sentence on a single line.
Hitting enter at the end of this line places the caret on the next line, indented to a depth of one.
Pressing enter again places the caret at on the next line, but without an indent, leaving the indent present on the previous line.
This is frustrating to work with as, when writing documents in a format such as Markdown, I constantly have to dedent lines.
Any ideas on this one?
The text was updated successfully, but these errors were encountered: