Skip to content

Commit

Permalink
GetSelectedText() => GetSelectedTextTemp()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed May 22, 2024
1 parent 7a90299 commit 51a9869
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void UpdateTextSelection(MainWindow* win, bool select) {
// isTextSelectionOut is set to true if this is text-only selection (as opposed to
// rectangular selection)
// caller needs to str::Free() the result
char* GetSelectedText(WindowTab* tab, const char* lineSep, bool& isTextOnlySelectionOut) {
TempStr GetSelectedTextTemp(WindowTab* tab, const char* lineSep, bool& isTextOnlySelectionOut) {
if (!tab || !tab->selectionOnPage) {
return nullptr;
}
Expand All @@ -223,11 +223,11 @@ char* GetSelectedText(WindowTab* tab, const char* lineSep, bool& isTextOnlySelec
isTextOnlySelectionOut = dm->textSelection->result.len > 0;
if (isTextOnlySelectionOut) {
WCHAR* s = dm->textSelection->ExtractText(lineSep);
char* res = ToUtf8(s);
TempStr res = ToUtf8Temp(s);
str::Free(s);
return res;
}
StrVec selections;
StrVec2 selections;
for (SelectionOnPage& sel : *tab->selectionOnPage) {
char* text = dm->GetTextInRegion(sel.pageNo, sel.rect);
if (!str::IsEmpty(text)) {
Expand All @@ -238,7 +238,7 @@ char* GetSelectedText(WindowTab* tab, const char* lineSep, bool& isTextOnlySelec
if (selections.Size() == 0) {
return nullptr;
}
char* s = Join(selections, lineSep);
TempStr s = JoinTemp(selections, lineSep);
return s;
}

Expand All @@ -255,21 +255,20 @@ void CopySelectionToClipboard(MainWindow* win) {
};

DisplayModel* dm = win->AsFixed();
char* selText = nullptr;
TempStr selText = nullptr;
bool isTextOnlySelectionOut = false;
if (!gDisableDocumentRestrictions && (dm && !dm->GetEngine()->AllowsCopyingText())) {
NotificationCreateArgs args;
args.hwndParent = win->hwndCanvas;
args.msg = _TRA("Copying text was denied (copying as image only)");
ShowNotification(args);
} else {
selText = GetSelectedText(tab, "\r\n", isTextOnlySelectionOut);
selText = GetSelectedTextTemp(tab, "\r\n", isTextOnlySelectionOut);
}

if (!str::IsEmpty(selText)) {
AppendTextToClipboard(selText);
}
str::Free(selText);

if (isTextOnlySelectionOut) {
// don't also copy the first line of a text selection as an image
Expand Down
2 changes: 1 addition & 1 deletion src/Selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ bool NeedsSelectionEdgeAutoscroll(MainWindow* win, int x, int y);
void OnSelectionEdgeAutoscroll(MainWindow* win, int x, int y);
void OnSelectionStart(MainWindow* win, int x, int y, WPARAM key);
void OnSelectionStop(MainWindow* win, int x, int y, bool aborted);
char* GetSelectedText(WindowTab* tab, const char* lineSep, bool& isTextOnlySelectionOut);
TempStr GetSelectedTextTemp(WindowTab* tab, const char* lineSep, bool& isTextOnlySelectionOut);
3 changes: 1 addition & 2 deletions src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4701,7 +4701,7 @@ static void LaunchBrowserWithSelection(WindowTab* tab, const WCHAR* urlPattern)
#endif

bool isTextOnlySelectionOut; // if false, a rectangular selection
char* selText = GetSelectedText(tab, "\n", isTextOnlySelectionOut);
TempStr selText = GetSelectedTextTemp(tab, "\n", isTextOnlySelectionOut);
if (!selText) {
return;
}
Expand All @@ -4721,7 +4721,6 @@ static void LaunchBrowserWithSelection(WindowTab* tab, const WCHAR* urlPattern)
Replace(url, kUserLangStr, langW);
char* uri = ToUtf8Temp(url.Get());
LaunchBrowser(uri);
str::Free(selText);
}

// TODO: rather arbitrary divide of responsibility between this and CopySelectionToClipboard()
Expand Down

0 comments on commit 51a9869

Please sign in to comment.