mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: copy underline
This commit is contained in:
parent
68a1acc9f2
commit
ee80fd5d97
@ -46,6 +46,13 @@ class Selection {
|
|||||||
(start.path <= end.path && !pathEquals(start.path, end.path)) ||
|
(start.path <= end.path && !pathEquals(start.path, end.path)) ||
|
||||||
(isSingle && start.offset < end.offset);
|
(isSingle && start.offset < end.offset);
|
||||||
|
|
||||||
|
Selection normalize() {
|
||||||
|
if (isForward) {
|
||||||
|
return Selection(start: end, end: start);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
Selection get reversed => copyWith(start: end, end: start);
|
Selection get reversed => copyWith(start: end, end: start);
|
||||||
|
|
||||||
Selection collapse({bool atStart = false}) {
|
Selection collapse({bool atStart = false}) {
|
||||||
|
@ -18,6 +18,7 @@ const String tagParagraph = "p";
|
|||||||
const String tagImage = "img";
|
const String tagImage = "img";
|
||||||
const String tagAnchor = "a";
|
const String tagAnchor = "a";
|
||||||
const String tagBold = "b";
|
const String tagBold = "b";
|
||||||
|
const String tagUnderline = "u";
|
||||||
const String tagStrong = "strong";
|
const String tagStrong = "strong";
|
||||||
const String tagSpan = "span";
|
const String tagSpan = "span";
|
||||||
const String tagCode = "code";
|
const String tagCode = "code";
|
||||||
@ -54,7 +55,8 @@ class HTMLToNodesConverter {
|
|||||||
if (child.localName == tagAnchor ||
|
if (child.localName == tagAnchor ||
|
||||||
child.localName == tagSpan ||
|
child.localName == tagSpan ||
|
||||||
child.localName == tagCode ||
|
child.localName == tagCode ||
|
||||||
child.localName == tagStrong) {
|
child.localName == tagStrong ||
|
||||||
|
child.localName == tagUnderline) {
|
||||||
_handleRichTextElement(delta, child);
|
_handleRichTextElement(delta, child);
|
||||||
} else if (child.localName == tagBold) {
|
} else if (child.localName == tagBold) {
|
||||||
// Google docs wraps the the content inside the `<b></b>` tag.
|
// Google docs wraps the the content inside the `<b></b>` tag.
|
||||||
@ -203,6 +205,8 @@ class HTMLToNodesConverter {
|
|||||||
delta.insert(element.text, attributes);
|
delta.insert(element.text, attributes);
|
||||||
} else if (element.localName == tagStrong || element.localName == tagBold) {
|
} else if (element.localName == tagStrong || element.localName == tagBold) {
|
||||||
delta.insert(element.text, {"bold": true});
|
delta.insert(element.text, {"bold": true});
|
||||||
|
} else if (element.localName == tagUnderline) {
|
||||||
|
delta.insert(element.text, {"underline": true});
|
||||||
} else {
|
} else {
|
||||||
delta.insert(element.text);
|
delta.insert(element.text);
|
||||||
}
|
}
|
||||||
@ -454,6 +458,11 @@ class NodesToHTMLConverter {
|
|||||||
final strong = html.Element.tag(tagStrong);
|
final strong = html.Element.tag(tagStrong);
|
||||||
strong.append(html.Text(op.content));
|
strong.append(html.Text(op.content));
|
||||||
childNodes.add(strong);
|
childNodes.add(strong);
|
||||||
|
} else if (attributes.length == 1 &&
|
||||||
|
attributes[StyleKey.underline] == true) {
|
||||||
|
final strong = html.Element.tag(tagUnderline);
|
||||||
|
strong.append(html.Text(op.content));
|
||||||
|
childNodes.add(strong);
|
||||||
} else {
|
} else {
|
||||||
final span = html.Element.tag(tagSpan);
|
final span = html.Element.tag(tagSpan);
|
||||||
final cssString = _attributesToCssStyle(attributes);
|
final cssString = _attributesToCssStyle(attributes);
|
||||||
|
@ -6,10 +6,11 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:rich_clipboard/rich_clipboard.dart';
|
import 'package:rich_clipboard/rich_clipboard.dart';
|
||||||
|
|
||||||
_handleCopy(EditorState editorState) async {
|
_handleCopy(EditorState editorState) async {
|
||||||
final selection = editorState.cursorSelection;
|
var selection = editorState.cursorSelection;
|
||||||
if (selection == null || selection.isCollapsed) {
|
if (selection == null || selection.isCollapsed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
selection = selection.normalize();
|
||||||
if (pathEquals(selection.start.path, selection.end.path)) {
|
if (pathEquals(selection.start.path, selection.end.path)) {
|
||||||
final nodeAtPath = editorState.document.nodeAtPath(selection.end.path)!;
|
final nodeAtPath = editorState.document.nodeAtPath(selection.end.path)!;
|
||||||
if (nodeAtPath.type == "text") {
|
if (nodeAtPath.type == "text") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user