Moved text selection utils to td_ui.

This commit is contained in:
23rd
2021-07-26 06:59:25 +03:00
parent 793f748d2e
commit 6e2f8eb9a7
23 changed files with 89 additions and 52 deletions

View File

@@ -0,0 +1,42 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "layout/layout_selection.h"
bool IsSubGroupSelection(TextSelection selection) {
return (selection.from == 0xFFFF) && (selection.to != 0xFFFF);
}
bool IsGroupItemSelection(
TextSelection selection,
int index) {
Expects(index >= 0 && index < 0x0F);
return IsSubGroupSelection(selection) && (selection.to & (1 << index));
}
TextSelection AddGroupItemSelection(
TextSelection selection,
int index) {
Expects(index >= 0 && index < 0x0F);
const auto bit = uint16(1U << index);
return TextSelection(
0xFFFF,
IsSubGroupSelection(selection) ? (selection.to | bit) : bit);
}
TextSelection RemoveGroupItemSelection(
TextSelection selection,
int index) {
Expects(index >= 0 && index < 0x0F);
const auto bit = uint16(1U << index);
return IsSubGroupSelection(selection)
? TextSelection(0xFFFF, selection.to & ~bit)
: selection;
}

View File

@@ -0,0 +1,26 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "ui/text/text.h"
constexpr auto FullSelection = TextSelection { 0xFFFF, 0xFFFF };
[[nodiscard]] bool IsSubGroupSelection(TextSelection selection);
[[nodiscard]] bool IsGroupItemSelection(
TextSelection selection,
int index);
[[nodiscard]] TextSelection AddGroupItemSelection(
TextSelection selection,
int index);
[[nodiscard]] TextSelection RemoveGroupItemSelection(
TextSelection selection,
int index);