Skip to content

Commit

Permalink
Migrate to the new version of super clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Dec 28, 2023
1 parent 5e5544a commit a15612f
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 89 deletions.
5 changes: 2 additions & 3 deletions example/lib/screens/settings/cubit/settings_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart' show ThemeMode;
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart' show HydratedMixin;
import 'package:hydrated_bloc/hydrated_bloc.dart' show HydratedCubit;

part 'settings_state.dart';
part 'settings_cubit.freezed.dart';
part 'settings_cubit.g.dart';

class SettingsCubit extends Cubit<SettingsState> with HydratedMixin {
class SettingsCubit extends HydratedCubit<SettingsState> {
SettingsCubit() : super(const SettingsState());

void updateSettings(SettingsState newSettingsState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ class ImageOptionsMenu extends StatelessWidget {
);

final data = await convertImageToUint8List(image);
final clipboard = SystemClipboard.instance;
if (data != null) {
final item = DataWriterItem()..add(Formats.png(data));
await ClipboardWriter.instance.write([item]);
await clipboard?.write([item]);
}
navigator.pop();
},
Expand Down
26 changes: 13 additions & 13 deletions lib/src/l10n/generated/quill_localizations_ar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,25 @@ class FlutterQuillLocalizationsAr extends FlutterQuillLocalizations {
String get headerStyle => 'ستايل العنوان';

@override
String get normal => 'Normal';
String get normal => 'عادي';

@override
String get heading1 => 'Heading 1';
String get heading1 => 'ترويسة ١';

@override
String get heading2 => 'Heading 2';
String get heading2 => 'ترويسة ٢';

@override
String get heading3 => 'Heading 3';
String get heading3 => 'ترويسة ٣';

@override
String get heading4 => 'Heading 4';
String get heading4 => 'ترويسة ٤';

@override
String get heading5 => 'Heading 5';
String get heading5 => 'ترويسة ٥';

@override
String get heading6 => 'Heading 6';
String get heading6 => 'ترويسة ٦';

@override
String get numberedList => 'قائمة مرقمة';
Expand Down Expand Up @@ -249,20 +249,20 @@ class FlutterQuillLocalizationsAr extends FlutterQuillLocalizations {
String get insertImage => 'إدراج صورة';

@override
String get pickAPhotoFromYourGallery => 'Pick a photo from your gallery';
String get pickAPhotoFromYourGallery => 'اختيار صورة من معرض الصور';

@override
String get takeAPhotoUsingYourCamera => 'Take a photo using your camera';
String get takeAPhotoUsingYourCamera => 'التقاط صورة باستخدام الكاميرا';

@override
String get pasteAPhotoUsingALink => 'Paste a photo using a link';
String get pasteAPhotoUsingALink => 'لصق صورة باستخدام رابط';

@override
String get pickAVideoFromYourGallery => 'Pick a video from your gallery';
String get pickAVideoFromYourGallery => 'اختيار فيديو من معرض الفيديو';

@override
String get recordAVideoUsingYourCamera => 'Record a video using your camera';
String get recordAVideoUsingYourCamera => 'تسجيل فيديو باستخدام الكاميرا';

@override
String get pasteAVideoUsingALink => 'Paste a video using a link';
String get pasteAVideoUsingALink => 'لصق فيديو باستخدام رابط';
}
15 changes: 14 additions & 1 deletion lib/src/l10n/quill_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
"photo": "صورة",
"image": "صورة",
"caseSensitivityAndWholeWordSearch": "حالة الحساسية والبحث عن كلمة كاملة",
"insertImage": "إدراج صورة"
"insertImage": "إدراج صورة",
"normal": "عادي",
"heading1": "ترويسة ١",
"heading2": "ترويسة ٢",
"heading3": "ترويسة ٣",
"heading4": "ترويسة ٤",
"heading5": "ترويسة ٥",
"heading6": "ترويسة ٦",
"pickAPhotoFromYourGallery": "اختيار صورة من معرض الصور",
"takeAPhotoUsingYourCamera": "التقاط صورة باستخدام الكاميرا",
"pasteAPhotoUsingALink": "لصق صورة باستخدام رابط",
"pickAVideoFromYourGallery": "اختيار فيديو من معرض الفيديو",
"recordAVideoUsingYourCamera": "تسجيل فيديو باستخدام الكاميرا",
"pasteAVideoUsingALink": "لصق فيديو باستخدام رابط"
}

16 changes: 0 additions & 16 deletions lib/src/l10n/untranslated.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
{
"ar": [
"normal",
"heading1",
"heading2",
"heading3",
"heading4",
"heading5",
"heading6",
"pickAPhotoFromYourGallery",
"takeAPhotoUsingYourCamera",
"pasteAPhotoUsingALink",
"pickAVideoFromYourGallery",
"recordAVideoUsingYourCamera",
"pasteAVideoUsingALink"
],

"bg": [
"normal",
"heading1",
Expand Down
116 changes: 61 additions & 55 deletions lib/src/widgets/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,22 @@ class QuillRawEditorState extends EditorState
return;
}

if (controller.copiedImageUrl != null) {
// When image copied internally in the editor
final copiedImageUrl = controller.copiedImageUrl;
if (copiedImageUrl != null) {
final index = textEditingValue.selection.baseOffset;
final length = textEditingValue.selection.extentOffset - index;
final copied = controller.copiedImageUrl!;
controller.replaceText(
index,
length,
BlockEmbed.image(copied.url),
BlockEmbed.image(copiedImageUrl.url),
null,
);
if (copied.styleString.isNotEmpty) {
if (copiedImageUrl.styleString.isNotEmpty) {
controller.formatText(
getEmbedNode(controller, index + 1).offset,
1,
StyleAttribute(copied.styleString),
StyleAttribute(copiedImageUrl.styleString),
);
}
controller.copiedImageUrl = null;
Expand All @@ -206,46 +207,49 @@ class QuillRawEditorState extends EditorState
return;
}

// TODO: Bug, Doesn't replace the selected text, it just add a new one
final clipboard = SystemClipboard.instance;

final reader = await ClipboardReader.readClipboard();
if (reader.canProvide(Formats.htmlText)) {
final html = await reader.readValue(Formats.htmlText);
if (html == null) {
return;
}
final deltaFromCliboard = Document.fromHtml(html);
var newDelta = Delta();
newDelta = newDelta.compose(deltaFromCliboard);
if (!controller.document.isEmpty()) {
newDelta = newDelta.compose(controller.document.toDelta());
}
if (clipboard != null) {
// TODO: Bug, Doesn't replace the selected text, it just add a new one
final reader = await clipboard.read();
if (reader.canProvide(Formats.htmlText)) {
final html = await reader.readValue(Formats.htmlText);
if (html == null) {
return;
}
final deltaFromClipboard = Document.fromHtml(html);
var newDelta = Delta();
newDelta = newDelta.compose(deltaFromClipboard);
if (!controller.document.isEmpty()) {
newDelta = newDelta.compose(controller.document.toDelta());
}

controller
..setContents(
newDelta,
)
..updateSelection(
TextSelection.collapsed(
offset: controller.document.length,
),
ChangeSource.local,
);
controller
..setContents(
newDelta,
)
..updateSelection(
TextSelection.collapsed(
offset: controller.document.length,
),
ChangeSource.local,
);

bringIntoView(textEditingValue.selection.extent);
bringIntoView(textEditingValue.selection.extent);

// Collapse the selection and hide the toolbar and handles.
userUpdateTextEditingValue(
TextEditingValue(
text: textEditingValue.text,
selection: TextSelection.collapsed(
offset: textEditingValue.selection.end,
// Collapse the selection and hide the toolbar and handles.
userUpdateTextEditingValue(
TextEditingValue(
text: textEditingValue.text,
selection: TextSelection.collapsed(
offset: textEditingValue.selection.end,
),
),
),
cause,
);
cause,
);

return;
return;
}
}

// Snapshot the input before using `await`.
Expand Down Expand Up @@ -279,25 +283,27 @@ class QuillRawEditorState extends EditorState

final onImagePaste = widget.configurations.onImagePaste;
if (onImagePaste != null) {
final reader = await ClipboardReader.readClipboard();
if (!reader.canProvide(Formats.png)) {
return;
}
reader.getFile(Formats.png, (value) async {
final image = value;

final imageUrl = await onImagePaste(await image.readAll());
if (imageUrl == null) {
if (clipboard != null) {
final reader = await clipboard.read();
if (!reader.canProvide(Formats.png)) {
return;
}
reader.getFile(Formats.png, (value) async {
final image = value;

controller.replaceText(
textEditingValue.selection.end,
0,
BlockEmbed.image(imageUrl),
null,
);
});
final imageUrl = await onImagePaste(await image.readAll());
if (imageUrl == null) {
return;
}

controller.replaceText(
textEditingValue.selection.end,
0,
BlockEmbed.image(imageUrl),
null,
);
});
}
}
}

Expand Down

0 comments on commit a15612f

Please sign in to comment.