Add title case macro docs IJSDK-698

This commit is contained in:
JohnHake 2020-03-17 18:38:07 -07:00
parent b48295a48b
commit 410c40f937
4 changed files with 6 additions and 14 deletions

View File

@ -16,12 +16,9 @@ repositories {
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version 'LATEST-EAP-SNAPSHOT'
// Sets <idea-version> in plugin.xml
version '201-EAP-SNAPSHOT'
sameSinceUntilBuild = true
}
patchPluginXml {
// Sets <version> in plugin.xml
version = project.version
}

View File

@ -8,7 +8,6 @@ import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
public class TitleCaseMacro extends MacroBase {
public TitleCaseMacro() {
super("titleCase", "titleCase(String)");
}
@ -22,9 +21,11 @@ public class TitleCaseMacro extends MacroBase {
@Override
protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) {
// Retrieve the text from the macro or selection, if any is available.
String text = getTextResult(params, context, true);
if (text != null) {
if (text.length() > 0) {
// Capitalize the start of every word
text = StringUtil.toTitleCase(text);
}
return new TextResult(text);

View File

@ -2,15 +2,12 @@
<idea-plugin>
<!-- Unique id for this plugin. Must stay constant for the life of the plugin. -->
<id>org.intellij.sdk.liveTemplates</id>
<!-- Text to display as name on Preferences/Settings | Plugin page -->
<name>SDK: Live Templates Sample Project</name>
<!-- The <version> of this plugin is set by patchPluginXml.version in build.gradle -->
<!-- The <idea-version> compatibility of this plugin is set by intellij.sameSinceUntilBuild in build.gradle -->
<!-- Product and plugin compatibility requirements -->
<depends>com.intellij.modules.lang</depends>
@ -34,11 +31,8 @@
<vendor url="https://plugins.jetbrains.com">IntelliJ Platform SDK</vendor>
<extensions defaultExtensionNs="com.intellij">
<!-- Declare where the IntelliJ Platform should look to find XML-based Live Templates -->
<defaultLiveTemplates file="/liveTemplates/Markdown"/>
<!-- Declare the implementation for determining the context for applying Live Templates -->
<defaultLiveTemplates file="/liveTemplates/Markdown.xml"/>
<liveTemplateContext implementation="org.intellij.sdk.liveTemplates.MarkdownContext"/>
<!-- Declare implementation-based Live Template -->
<liveTemplateMacro implementation="org.intellij.sdk.liveTemplates.TitleCaseMacro"/>
</extensions>

View File

@ -15,7 +15,7 @@
description="SDK: Convert to title case"
toReformat="true"
toShortenFQNames="false">
<variable name="TITLE" expression="titleCase(SELECTION)" defaultValue="the quick brown fox jumped over the lazy dog" alwaysStopAt="true" />
<variable name="TITLE" expression="titleCase(SELECTION)" defaultValue="the quick brown fox" alwaysStopAt="true" />
<context>
<option name="MARKDOWN" value="true" />
</context>