Skip to content

Commit

Permalink
Add prompt to copy line to clipboard on long press
Browse files Browse the repository at this point in the history
Closes #56
  • Loading branch information
mhoran committed Mar 2, 2024
1 parent 376bdc1 commit cb896fa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@shopify/flash-list": "^1.6.3",
"date-fns": "^3.3.1",
"expo": "~50.0.8",
"expo-clipboard": "~5.0.1",
"expo-notifications": "~0.27.6",
"expo-updates": "~0.24.11",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/weechat/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class WeechatConnection {
}

onmessage(event: WebSocketMessageEvent): void {
const parsed = protocol.parse(event.data) as WeechatResponse<unknown>;
const parsed = protocol.parse(event.data);

if (parsed.id == 'version') {
this.authenticating = false;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/weechat/parser.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class WeeChatProtocol {
static rawText2Rich(input);
static rawText2Rich(input: string): AttributedStringNode[];

parse(data, optionsValues?);
parse(data: ArrayBuffer): WeechatResponse<unknown>;
}
2 changes: 1 addition & 1 deletion src/usecase/buffers/ui/Buffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import BufferLine from './BufferLine';
interface Props {
lines: WeechatLine[];
lastReadLine?: string;
onLongPress: () => void;
onLongPress: (line: WeechatLine) => void;
parseArgs: ParseShape[];
bufferId: string;
fetchMoreLines: (lines: number) => void;
Expand Down
21 changes: 19 additions & 2 deletions src/usecase/buffers/ui/BufferContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { renderWeechatFormat } from '../../../lib/weechat/color-formatter';
import { StoreState } from '../../../store';
import Buffer from './Buffer';
import UndoTextInput from './UndoTextInput';
import * as Clipboard from 'expo-clipboard';
import { WeeChatProtocol } from '../../../lib/weechat/parser';

const connector = connect(
(state: StoreState, { bufferId }: { bufferId: string }) => ({
Expand Down Expand Up @@ -165,8 +167,23 @@ class BufferContainer extends React.Component<Props, State> {
this.setState({ selection });
};

onLongPress = () => {
// not implemented
onLongPress = (line: WeechatLine) => {
const formattedPrefix = WeeChatProtocol.rawText2Rich(line.prefix);
const prefix = formattedPrefix.map((node) => node.text);
const formattedMessage = WeeChatProtocol.rawText2Rich(line.message);
const message = formattedMessage.map((node) => node.text);

ActionSheetIOS.showActionSheetWithOptions(
{ options: ['Copy', 'Cancel'], cancelButtonIndex: 2 },
() => {
const encloseNick =
line.tags_array.includes('irc_privmsg') &&
!line.tags_array.includes('irc_action');
Clipboard.setStringAsync(
`${encloseNick ? '<' : ''}${prefix.join('')}${encloseNick ? '>' : ''} ${message.join('')}`
);
}
);
};

render() {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5043,6 +5043,11 @@ expo-asset@~9.0.2:
invariant "^2.2.4"
md5-file "^3.2.3"

expo-clipboard@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/expo-clipboard/-/expo-clipboard-5.0.1.tgz#a62a021a9444740d180d60f915cca8242a323716"
integrity sha512-JH853QJPr5W3h87If3aDTnMK+ESSIrwzU2TdfZrqZttVDY2pMIf/w37mVHHNYodXM4ATHXadtOkjKbAa0DWwUg==

expo-constants@~15.4.0:
version "15.4.5"
resolved "https://registry.yarnpkg.com/expo-constants/-/expo-constants-15.4.5.tgz#81756a4c4e1c020f840a419cd86a124a6d1fb35b"
Expand Down

0 comments on commit cb896fa

Please sign in to comment.