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)) ||
|
||||
(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 collapse({bool atStart = false}) {
|
||||
|
@ -18,6 +18,7 @@ const String tagParagraph = "p";
|
||||
const String tagImage = "img";
|
||||
const String tagAnchor = "a";
|
||||
const String tagBold = "b";
|
||||
const String tagUnderline = "u";
|
||||
const String tagStrong = "strong";
|
||||
const String tagSpan = "span";
|
||||
const String tagCode = "code";
|
||||
@ -54,7 +55,8 @@ class HTMLToNodesConverter {
|
||||
if (child.localName == tagAnchor ||
|
||||
child.localName == tagSpan ||
|
||||
child.localName == tagCode ||
|
||||
child.localName == tagStrong) {
|
||||
child.localName == tagStrong ||
|
||||
child.localName == tagUnderline) {
|
||||
_handleRichTextElement(delta, child);
|
||||
} else if (child.localName == tagBold) {
|
||||
// Google docs wraps the the content inside the `<b></b>` tag.
|
||||
@ -203,6 +205,8 @@ class HTMLToNodesConverter {
|
||||
delta.insert(element.text, attributes);
|
||||
} else if (element.localName == tagStrong || element.localName == tagBold) {
|
||||
delta.insert(element.text, {"bold": true});
|
||||
} else if (element.localName == tagUnderline) {
|
||||
delta.insert(element.text, {"underline": true});
|
||||
} else {
|
||||
delta.insert(element.text);
|
||||
}
|
||||
@ -454,6 +458,11 @@ class NodesToHTMLConverter {
|
||||
final strong = html.Element.tag(tagStrong);
|
||||
strong.append(html.Text(op.content));
|
||||
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 {
|
||||
final span = html.Element.tag(tagSpan);
|
||||
final cssString = _attributesToCssStyle(attributes);
|
||||
|
@ -6,10 +6,11 @@ import 'package:flutter/services.dart';
|
||||
import 'package:rich_clipboard/rich_clipboard.dart';
|
||||
|
||||
_handleCopy(EditorState editorState) async {
|
||||
final selection = editorState.cursorSelection;
|
||||
var selection = editorState.cursorSelection;
|
||||
if (selection == null || selection.isCollapsed) {
|
||||
return;
|
||||
}
|
||||
selection = selection.normalize();
|
||||
if (pathEquals(selection.start.path, selection.end.path)) {
|
||||
final nodeAtPath = editorState.document.nodeAtPath(selection.end.path)!;
|
||||
if (nodeAtPath.type == "text") {
|
||||
|
Loading…
Reference in New Issue
Block a user