Skip to content

Commit e6bf2a4

Browse files
committed
paste_to_replace 옵션 추가
1 parent 6be47ca commit e6bf2a4

7 files changed

Lines changed: 49 additions & 11 deletions

File tree

Typoon/match/match.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ struct Match
2323
bool doNeedFullComposite;
2424
bool doKeepComposite;
2525
bool isKorEngInsensitive;
26+
bool doPasteToReplace;
2627
};

Typoon/match/trigger_tree.cpp

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void TriggerTree::Reconstruct(std::string_view matchesString, std::function<void
162162
{
163163
const auto& [originalTriggers, originalReplace, replaceImage, replaceCommand,
164164
isCaseSensitive, isWord, doPropagateCase, uppercaseStyle,
165-
doNeedFullComposite, doKeepComposite, isKorEngInsensitive] = match;
165+
doNeedFullComposite, doKeepComposite, isKorEngInsensitive, doPasteToReplace] = match;
166166

167167
std::vector<std::wstring> triggers;
168168
if (isKorEngInsensitive)
@@ -209,7 +209,8 @@ void TriggerTree::Reconstruct(std::string_view matchesString, std::function<void
209209
// TODO: Abstract the extra conditions of the options and warn the user if ignored
210210
.propagateCase = doPropagateCase && !isCaseSensitive && replaceType == Ending::EReplaceType::TEXT,
211211
.uppercaseStyle = uppercaseStyle,
212-
.keepComposite = doKeepComposite && is_korean(replace.back()) && replaceType == Ending::EReplaceType::TEXT,
212+
.keepComposite = doKeepComposite && is_korean(replace.back()) && replaceType == Ending::EReplaceType::TEXT && !doPasteToReplace,
213+
.pasteToReplace = doPasteToReplace || replaceType == Ending::EReplaceType::IMAGE,
213214
};
214215

215216
const EndingMetaData endingMetaDataBase{
@@ -617,7 +618,7 @@ void TriggerTree::OnInput(const InputMessage(&inputs)[MAX_INPUT_COUNT], int leng
617618
void TriggerTree::replaceString(const Ending& ending, const Agent& agent, std::wstring_view stroke, const InputMessage(&inputs)[MAX_INPUT_COUNT], int inputLength, int inputIndex, bool doNeedFullComposite)
618619
{
619620
const auto& [replaceStringIndex, replaceType, replaceStringLength, backspaceCount, cursorMoveCount,
620-
propagateCase, uppercaseStyle, keepComposite] = ending;
621+
propagateCase, uppercaseStyle, keepComposite, pasteToReplace] = ending;
621622

622623
const std::wstring_view originalReplaceString{ mReplaceStrings.data() + replaceStringIndex, replaceStringLength };
623624

@@ -646,10 +647,20 @@ void TriggerTree::replaceString(const Ending& ending, const Agent& agent, std::w
646647
{
647648
std::vector<FakeInput> fakeInputs{ backspaceCount, FakeInput{ FakeInput::EType::KEY, FakeInput::BACKSPACE_KEY } };
648649
const auto& [str, ret] = run_command_and_get_output(originalReplaceString);
649-
fakeInputs.reserve(fakeInputs.size() + str.size());
650-
for (wchar_t c : str)
650+
if (pasteToReplace)
651651
{
652-
fakeInputs.emplace_back(FakeInput::EType::LETTER, c);
652+
push_current_clipboard_state();
653+
set_clipboard_text(str);
654+
// Popping the clipboard state is done in main.
655+
fakeInputs.emplace_back(FakeInput::EType::HOT_KEY_PASTE);
656+
}
657+
else
658+
{
659+
fakeInputs.reserve(fakeInputs.size() + str.size());
660+
for (wchar_t c : str)
661+
{
662+
fakeInputs.emplace_back(FakeInput::EType::LETTER, c);
663+
}
653664
}
654665
send_fake_inputs(fakeInputs, false);
655666
return;
@@ -820,6 +831,28 @@ void TriggerTree::replaceString(const Ending& ending, const Agent& agent, std::w
820831

821832
std::fill_n(std::back_inserter(fakeInputs), cursorMoveCount + additionalCursorMoveCount, FakeInput{ FakeInput::EType::KEY, FakeInput::LEFT_ARROW_KEY });
822833

834+
if (pasteToReplace)
835+
{
836+
const auto firstLetter = std::ranges::find(fakeInputs, FakeInput::EType::LETTER, &FakeInput::type);
837+
const auto end = fakeInputs.end();
838+
if (firstLetter != end)
839+
{
840+
const auto lastLetter = std::find_if(firstLetter, end, [](const FakeInput& input) { return input.type != FakeInput::EType::LETTER; });
841+
std::wstring str;
842+
str.reserve(std::distance(firstLetter, lastLetter));
843+
for (auto it = firstLetter; it != lastLetter; ++it)
844+
{
845+
str += it->letter;
846+
}
847+
848+
push_current_clipboard_state();
849+
set_clipboard_text(str);
850+
// Popping the clipboard state is done in main.
851+
*firstLetter = FakeInput{ .type = FakeInput::EType::HOT_KEY_PASTE };
852+
fakeInputs.erase(firstLetter + 1, lastLetter);
853+
}
854+
}
855+
823856
for (FakeInput& fakeInput : fakeInputs)
824857
{
825858
if (fakeInput.type == FakeInput::EType::LETTER && fakeInput.letter == '\n')

Typoon/match/trigger_tree.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ struct Ending
7474
unsigned int cursorMoveCount = 0;
7575
bool propagateCase = false; // Won't be true if the first letter is not cased.
7676
Match::EUppercaseStyle uppercaseStyle = Match::EUppercaseStyle::FIRST_LETTER; // Only used if `propagateCase` is true.
77-
bool keepComposite = false; // Won't be true if the letter is not Korean or need full composite.
77+
bool keepComposite = false; // Won't be true if the letter is not Korean or need full composite or `pasteToReplace` is true.
78+
bool pasteToReplace = false;
7879
};
7980

8081

Typoon/parse/parse_match.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ OptionContainerForParse& OptionContainerForParse::operator|=(const OptionContain
1515
full_composite |= other.full_composite;
1616
keep_composite |= other.keep_composite;
1717
kor_eng_insensitive |= other.kor_eng_insensitive;
18+
paste_to_replace |= other.paste_to_replace;
1819

1920
return *this;
2021
}
@@ -33,6 +34,7 @@ MatchForParse::operator Match() const
3334
.doNeedFullComposite = full_composite,
3435
.doKeepComposite = keep_composite,
3536
.isKorEngInsensitive = kor_eng_insensitive,
37+
.doPasteToReplace = paste_to_replace,
3638
};
3739

3840
if (!triggers.empty())

Typoon/parse/parse_match.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ struct OptionContainerForParse
2626
bool full_composite = false;
2727
bool keep_composite = false;
2828
bool kor_eng_insensitive = false;
29+
bool paste_to_replace = false;
2930

3031
OptionContainerForParse& operator|=(const OptionContainerForParse& other);
3132

32-
JSON5_MEMBERS(case_sensitive, word, propagate_case, uppercase_style, full_composite, keep_composite, kor_eng_insensitive)
33+
JSON5_MEMBERS(case_sensitive, word, propagate_case, uppercase_style, full_composite, keep_composite, kor_eng_insensitive, paste_to_replace)
3334
};
3435

3536
struct MatchForParse : OptionContainerForParse

WindowsInstaller/Product.wxs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
33
<Product Id="*" Name="Typoon" Language="!(loc.Language)" Version="$(var.VersionNumber)" Manufacturer="Joonho Hwang" UpgradeCode="eefadce2-887c-4f86-b767-59c8c5e6a710">
4-
<Package InstallerVersion="400" Compressed="yes" InstallScope="perMachine" Comments="Typoon Copyright (C) 2023-2025 Joonho Hwang" Platform="x64" />
4+
<Package InstallerVersion="400" Compressed="yes" InstallScope="perMachine" Comments="Typoon Copyright (C) 2023-2026 Joonho Hwang" Platform="x64" />
55

66
<MajorUpgrade DowngradeErrorMessage="!(loc.NoDowngrade)" AllowSameVersionUpgrades="yes" />
77
<MediaTemplate EmbedCab="yes"/>

WindowsInstaller/WindowsInstaller.wixproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<DefineConstants>Debug;</DefineConstants>
3636
<WixVariables>
3737
</WixVariables>
38-
<CompilerAdditionalOptions>-dVersionNumber="0.2.1"</CompilerAdditionalOptions>
38+
<CompilerAdditionalOptions>-dVersionNumber="0.3.0"</CompilerAdditionalOptions>
3939
<LinkerAdditionalOptions>-ext WixUIExtension -ext WixUtilExtension</LinkerAdditionalOptions>
4040
</PropertyGroup>
4141
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
@@ -45,7 +45,7 @@
4545
</DefineConstants>
4646
<WixVariables>
4747
</WixVariables>
48-
<CompilerAdditionalOptions>-dVersionNumber="0.2.1"</CompilerAdditionalOptions>
48+
<CompilerAdditionalOptions>-dVersionNumber="0.3.0"</CompilerAdditionalOptions>
4949
<LinkerAdditionalOptions>-ext WixUIExtension -ext WixUtilExtension</LinkerAdditionalOptions>
5050
</PropertyGroup>
5151
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">

0 commit comments

Comments
 (0)