forked from gsantner/markor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TextAction: Add text case changing functionality (closes gsantner#2390,…
… PR gsantner#2426) * This commit introduces the ability to change text case within the editor, addressing issue gsantner#2390. Users can now toggle case, switch case, capitalize words, and capitalize sentences directly from the Edit menu. * Added an example to the display text of each text case.
Showing
6 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/main/java/net/gsantner/markor/util/TextCasingUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package net.gsantner.markor.util; | ||
|
||
public class TextCasingUtils { | ||
public static String toggleCase(String text) { // Toggle all text to Uppercase or Lowercase | ||
if (text.equals(text.toUpperCase())) { | ||
return text.toLowerCase(); | ||
} else { | ||
return text.toUpperCase(); | ||
} | ||
} | ||
|
||
public static String switchCase(String text) { // Switch the text case of each character | ||
StringBuilder result = new StringBuilder(); | ||
for (char c : text.toCharArray()) { | ||
if (Character.isUpperCase(c)) { | ||
result.append(Character.toLowerCase(c)); | ||
} else if (Character.isLowerCase(c)) { | ||
result.append(Character.toUpperCase(c)); | ||
} else { | ||
result.append(c); | ||
} | ||
} | ||
return result.toString(); | ||
} | ||
|
||
public static String capitalizeWords(String text) { // Capitalize the first letter of each word | ||
StringBuilder result = new StringBuilder(); | ||
boolean capitalizeNext = true; | ||
for (char c : text.toCharArray()) { | ||
if (Character.isWhitespace(c)) { | ||
capitalizeNext = true; | ||
result.append(c); | ||
} else if (capitalizeNext) { | ||
result.append(Character.toUpperCase(c)); | ||
capitalizeNext = false; | ||
} else { | ||
result.append(Character.toLowerCase(c)); | ||
} | ||
} | ||
return result.toString(); | ||
} | ||
|
||
public static String capitalizeSentences(String text) { // Capitalize the first letter of each sentence | ||
StringBuilder result = new StringBuilder(); | ||
boolean capitalizeNext = true; | ||
for (char c : text.toCharArray()) { | ||
if (c == '.' || c == '!' || c == '?') { | ||
capitalizeNext = true; | ||
result.append(c); | ||
} else if (Character.isWhitespace(c)) { | ||
result.append(c); | ||
} else if (capitalizeNext) { | ||
result.append(Character.toUpperCase(c)); | ||
capitalizeNext = false; | ||
} else { | ||
result.append(c); | ||
} | ||
} | ||
return result.toString(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/res/drawable/ic_format_text_case_black_24dp.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M16.51,3C16.82,3 17.1,3.2 17.21,3.5L22.71,19C22.85,19.39 22.64,19.82 22.25,19.96C21.86,20.1 21.43,19.89 21.29,19.5L19.87,15.5H12.76L11.2,19.52C11.05,19.91 10.62,20.1 10.23,19.95C9.84,19.8 9.65,19.37 9.8,18.98L15.8,3.48C15.91,3.19 16.2,3 16.51,3ZM16.47,5.91L13.34,14H19.34L16.47,5.91Z"/> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M5.5,10.5L5.79,10.51C7.75,10.61 8.91,11.74 9,13.56L9,13.76V19.26C9,19.64 8.72,19.95 8.35,20L8.25,20.01C7.87,20.01 7.56,19.73 7.51,19.36L7.5,19.26L7.5,19.16C6.51,19.72 5.6,20.01 4.75,20.01C2.91,20.01 1.5,18.72 1.5,16.76C1.5,15.04 2.69,13.75 4.66,13.52C5.59,13.4 6.54,13.47 7.5,13.73C7.49,12.62 6.94,12.07 5.71,12.01C4.75,11.96 4.07,12.1 3.68,12.37C3.34,12.61 2.87,12.53 2.63,12.19C2.4,11.85 2.48,11.38 2.82,11.15C3.47,10.69 4.37,10.48 5.5,10.5ZM7.5,15.32L7.2,15.23C6.39,15.01 5.6,14.95 4.84,15.04C3.61,15.19 3,15.85 3,16.8C3,17.89 3.71,18.55 4.75,18.55C5.43,18.55 6.27,18.23 7.25,17.58L7.5,17.41V15.32Z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters