Add caret position placeholder
This commit is contained in:
parent
d72198746f
commit
e7f3c6f80e
|
|
@ -30,7 +30,10 @@ class CreateFileWithFilenameTemplateAction(
|
|||
val contentPanel = NewItemSimplePopupPanel()
|
||||
val nameField = contentPanel.textField
|
||||
|
||||
nameField.text = placeholderProcessor.processTemplate(project, directory)
|
||||
val (filename, caretPosition) = placeholderProcessor.processTemplate(project, directory)
|
||||
|
||||
nameField.text = filename
|
||||
nameField.caretPosition = caretPosition
|
||||
|
||||
val popup = NewItemPopupUtil.createNewItemPopup(IdeBundle.message("title.new.file"), contentPanel, nameField)
|
||||
contentPanel.setApplyAction { event: InputEvent? ->
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import kotlin.math.max
|
|||
|
||||
class PlaceholderProcessor(private val template: String, private val placeholders: List<Placeholder>) {
|
||||
|
||||
fun processTemplate(project: Project, directory: PsiDirectory): String {
|
||||
fun processTemplate(project: Project, directory: PsiDirectory): ProcessedTemplate {
|
||||
var placeholderLevel = 0
|
||||
var placeholder = ""
|
||||
|
||||
|
|
@ -45,6 +45,13 @@ class PlaceholderProcessor(private val template: String, private val placeholder
|
|||
}
|
||||
}
|
||||
|
||||
return context.filename
|
||||
val caretPosition = when {
|
||||
context.filename.indexOf("{|}") != -1 -> context.filename.indexOf("{|}")
|
||||
context.filename.indexOfFirst { it == '.' } != -1 -> context.filename.indexOfFirst { it == '.' }
|
||||
else -> context.filename.length
|
||||
}
|
||||
context.filename = context.filename.replace("{|}", "")
|
||||
|
||||
return ProcessedTemplate(context.filename, caretPosition)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package de.idetools.filename_template.placeholders
|
||||
|
||||
data class ProcessedTemplate(
|
||||
val filename: String,
|
||||
val caretPosition: Int
|
||||
)
|
||||
|
|
@ -64,6 +64,9 @@
|
|||
The first available sequential number. Define the initial value and desired leading zeros in the template.
|
||||
Example: notes({042}).md => notes(042).md, notes(043).md, ...
|
||||
</dd>
|
||||
|
||||
<dt>{|}</dt>
|
||||
<dd>The caret position. If omitted the caret is positioned before the first '.' if available or at the end.</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user