-
-
Notifications
You must be signed in to change notification settings - Fork 84
Added action replace #135
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
Merged
Added action replace #135
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
300f152
added action replace
AndreasArvidsson 65961d9
unified token and line decoration style
AndreasArvidsson 040aeae
exported smaller functions for perform inside outside adjustment
AndreasArvidsson c10c617
cleanup
AndreasArvidsson 787b533
added options to get text action
AndreasArvidsson c37b102
clean up
AndreasArvidsson 5c08a0a
added support for inside and outside positions
AndreasArvidsson 5f47aff
default to space for missing delimiter
AndreasArvidsson 4c623a7
a just position for replace
AndreasArvidsson 97ad060
clean up a new selection
AndreasArvidsson 2292c86
fixed merged
AndreasArvidsson 2069d8a
cleanup
AndreasArvidsson 86309ea
Merged with dev
AndreasArvidsson f87082f
Rework delimiters
AndreasArvidsson dc54a95
cleanup
AndreasArvidsson a3ade00
Clean up
AndreasArvidsson ff198d4
Cleanup
pokey 4aad7c9
Fix
pokey 7645671
Better docs
pokey 161d8d2
whoops
pokey 84411d8
More clean up
pokey 2edc576
Minor doc tweak
pokey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,66 @@ | ||
import { | ||
Action, | ||
ActionPreferences, | ||
ActionReturnValue, | ||
Graph, | ||
TypedSelection, | ||
} from "../Types"; | ||
import displayPendingEditDecorations from "../editDisplayUtils"; | ||
import { runForEachEditor } from "../targetUtils"; | ||
import { flatten, zip } from "lodash"; | ||
import { maybeAddDelimiter } from "../getTextWithPossibleDelimiter"; | ||
import { performEditsAndUpdateSelections } from "../updateSelections"; | ||
|
||
export default class implements Action { | ||
AndreasArvidsson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
targetPreferences: ActionPreferences[] = [{ insideOutsideType: null }]; | ||
|
||
constructor(private graph: Graph) { | ||
this.run = this.run.bind(this); | ||
} | ||
|
||
async run( | ||
[targets]: [TypedSelection[]], | ||
texts: string[] | ||
): Promise<ActionReturnValue> { | ||
await displayPendingEditDecorations( | ||
targets, | ||
this.graph.editStyles.pendingModification0 | ||
); | ||
|
||
// Broadcast single text for each target | ||
if (texts.length === 1) { | ||
texts = Array(targets.length).fill(texts[0]); | ||
} | ||
|
||
if (targets.length !== texts.length) { | ||
throw new Error("Targets and texts must have same length"); | ||
} | ||
|
||
const edits = zip(targets, texts).map(([target, text]) => ({ | ||
editor: target!.selection.editor, | ||
range: target!.selection.selection, | ||
text: maybeAddDelimiter(text!, target!), | ||
})); | ||
|
||
const thatMark = flatten( | ||
await runForEachEditor( | ||
edits, | ||
(edit) => edit.editor, | ||
async (editor, edits) => { | ||
const [updatedSelections] = await performEditsAndUpdateSelections( | ||
editor, | ||
edits, | ||
[targets.map((target) => target.selection.selection)] | ||
); | ||
|
||
return updatedSelections.map((selection) => ({ | ||
editor, | ||
selection, | ||
})); | ||
} | ||
) | ||
); | ||
|
||
return { returnValue: null, thatMark }; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.