Skip to content

Commit

Permalink
Merge pull request #9 from anton-erofeev/sort-lines-action
Browse files Browse the repository at this point in the history
added sort lines action
  • Loading branch information
anton-erofeev authored Nov 17, 2024
2 parents fac7400 + ff9b20e commit 243c176
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## [Unreleased]

## [0.1.1] - 2024-11-17
### Added
- Added Shuffle Lines feature

## [0.1.0] - 2024-11-14
### Added
- Added Sort Lines by length ascending feature
Expand All @@ -21,3 +25,4 @@
[0.0.1]: https://github.com/anton-erofeev/line-sorter-intellij-plugin/commits/v0.0.1
[0.0.2]: https://github.com/anton-erofeev/line-sorter-intellij-plugin/commits/v0.0.2
[0.1.0]: https://github.com/anton-erofeev/line-sorter-intellij-plugin/commits/v0.1.0
[0.1.1]: https://github.com/anton-erofeev/line-sorter-intellij-plugin/commits/v0.1.1
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

## Description
<!-- Plugin description -->
Lines Sorter Pro is a handy tool for developers that lets you quickly sort lines within a file or just within a selected area.
This plugin adds a "Sort Lines" option to the editor's right-click Refactor menu, making line sorting easy and intuitive.
Lines Sorter Pro is a handy tool for developers that lets you quickly sort or shuffle lines within a file or just within a selected area.
The plugin adds multiple string sorting options, including alphabetical, by line length, and shuffle, to the editor's right-click Refactor menu, making it easy and intuitive to organize or mix up your content.

### **Key Features:**
- **Alphabetical Sorting:** Sort lines alphabetically. Supports both ascending (A-Z) and descending (Z-A) order.
- **Sorting by Line Length:** Sort lines based on their length. Supports both ascending (shortest to longest) and descending (longest to shortest) order.
- **Selected Lines Sorting:** If text is highlighted, the plugin sorts only the selected lines, leaving the rest of the file unchanged.
- **Full-File Sorting:** If no text is selected, all lines in the file are sorted alphabetically.
- **Shuffle Lines:** Randomly shuffle the lines in the selection or the entire file, providing a quick way to mix up content without sorting.

**Ideal for:**
Developers working with configuration files, property lists, text data, or any files where organized, readable line order improves workflow and readability.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = com.github.antonerofeev.linesorterintellijplugin
pluginName = line-sorter-intellij-plugin
pluginRepositoryUrl = https://github.com/anton-erofeev/line-sorter-intellij-plugin
# SemVer format -> https://semver.org
pluginVersion = 0.1.0
pluginVersion = 0.1.1

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 231
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.antonerofeev.linesorterintellijplugin.actions

import com.github.antonerofeev.linesorterintellijplugin.enums.SortOrder
import com.github.antonerofeev.linesorterintellijplugin.enums.SortType
import com.github.antonerofeev.linesorterintellijplugin.utils.LinesSorter
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys

class ShuffleLinesAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project
val editor = e.getData(CommonDataKeys.EDITOR)

LinesSorter.sort(project, editor, SortType.SHUFFLE, SortOrder.ASCENDING)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package com.github.antonerofeev.linesorterintellijplugin.enums

enum class SortType {
ALPHABETICAL,
BY_LENGTH
BY_LENGTH,
SHUFFLE
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object LinesSorter {
val sortedText = when (sortType) {
SortType.ALPHABETICAL -> sortAlphabetically(textToSort, sortOrder)
SortType.BY_LENGTH -> sortByLength(textToSort, sortOrder)
SortType.SHUFFLE -> shuffle(textToSort)
}

WriteCommandAction.runWriteCommandAction(project) {
Expand Down Expand Up @@ -84,4 +85,16 @@ object LinesSorter {
}
.collect(Collectors.joining("\n"))
}

/**
* Shuffles lines randomly.
*
* @param text The text to shuffle.
* @return The shuffled text.
*/
private fun shuffle(text: String): String {
val lines = text.split("\n".toRegex()).dropLastWhile { it.isEmpty() }.toMutableList()
lines.shuffle()
return lines.joinToString("\n")
}
}
10 changes: 8 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<resource-bundle>messages.MyBundle</resource-bundle>
<description><![CDATA[
Lines Sorter Pro is a handy tool for developers that lets you quickly sort lines within a file or just within a selected area.
This plugin adds a "Sort Lines" option to the editor's right-click Refactor menu, making line sorting easy and intuitive.
Lines Sorter Pro is a handy tool for developers that lets you quickly sort or shuffle lines within a file or just within a selected area.
The plugin adds multiple string sorting options, including alphabetical, by line length, and shuffle, to the editor's right-click Refactor menu, making it easy and intuitive to organize or mix up your content.
]]></description>

<actions>
Expand Down Expand Up @@ -45,6 +45,12 @@
text="Sort Lines By Length Descending"
description="Sort lines in a file by length in descending order">
</action>
<action
id="ShuffleLines"
class="com.github.antonerofeev.linesorterintellijplugin.actions.ShuffleLinesAction"
text="Shuffle Lines Randomly"
description="Shuffles lines randomly">
</action>
</group>

</actions>
Expand Down

0 comments on commit 243c176

Please sign in to comment.