• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

worktile / slate-angular / 62d89b67-8ca4-4331-8989-deca36ae2952

pending completion
62d89b67-8ca4-4331-8989-deca36ae2952

Pull #231

circleci

pubuzhixing8
chore: add changeset
Pull Request #231: Android compat

347 of 923 branches covered (37.59%)

Branch coverage included in aggregate %.

41 of 41 new or added lines in 3 files covered. (100.0%)

801 of 1587 relevant lines covered (50.47%)

49.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.19
/packages/src/components/string/string.component.ts
1
import { Component, OnInit, Input, ChangeDetectionStrategy, OnChanges, ElementRef, ViewContainerRef, AfterViewInit } from '@angular/core';
2
import { Editor, Path, Node } from 'slate';
3
import { ViewContainerItem } from '../../view/container-item';
4
import { SlateLeafContext, SlateStringContext } from '../../view/context';
5
import { AngularEditor } from '../../plugins/angular-editor';
6
import { SlateDefaultStringComponent } from './default-string.component';
7

8
@Component({
9
    selector: 'span[slateString]',
10
    template: '',
11
    changeDetection: ChangeDetectionStrategy.OnPush
12
})
13
export class SlateStringComponent extends ViewContainerItem<SlateStringContext> implements OnInit, OnChanges, AfterViewInit {
1✔
14
    @Input() context: SlateLeafContext;
15

16
    constructor(private elementRef: ElementRef<any>, protected viewContainerRef: ViewContainerRef) {
143✔
17
        super(viewContainerRef);
143✔
18
    }
19

20
    ngOnInit(): void {
21
        this.createView();
143✔
22
    }
23

24
    ngOnChanges() {
25
        if (!this.initialized) {
149✔
26
            return;
143✔
27
        }
28
        this.updateView();
6✔
29
    }
30

31
    ngAfterViewInit() {
32
        this.elementRef.nativeElement.remove();
143✔
33
    }
34

35
    getViewType() {
36
        const path = AngularEditor.findPath(this.viewContext.editor, this.context.text);
149✔
37
        const parentPath = Path.parent(path);
149✔
38

39
        // COMPAT: Render text inside void nodes with a zero-width space.
40
        // So the node can contain selection but the text is not visible.
41
        if (this.viewContext.editor.isVoid(this.context.parent)) {
149✔
42
            return this.viewContext.templateComponent.voidStringTemplate;
1✔
43
        }
44

45
        // COMPAT: If this is the last text node in an empty block, render a zero-
46
        // width space that will convert into a line break when copying and pasting
47
        // to support expected plain text.
48
        if (
148✔
49
            this.context.leaf.text === '' &&
178✔
50
            this.context.parent.children[this.context.parent.children.length - 1] === this.context.text &&
51
            !this.viewContext.editor.isInline(this.context.parent) &&
52
            Editor.string(this.viewContext.editor, parentPath) === ''
53
        ) {
54
            return SlateDefaultStringComponent;
10✔
55
        }
56

57
        // COMPAT: If the text is empty, it's because it's on the edge of an inline
58
        // node, so we render a zero-width space so that the selection can be
59
        // inserted next to it still.
60
        if (this.context.leaf.text === '') {
138!
61
            return this.viewContext.templateComponent.emptyTextTemplate;
×
62
        }
63

64
        // COMPAT: Browsers will collapse trailing new lines at the end of blocks,
65
        // so we need to add an extra trailing new lines to prevent that.
66
        if (this.context.isLast && this.context.leaf.text.slice(-1) === '\n') {
138!
67
            return this.viewContext.templateComponent.compatStringTemplate;
×
68
        }
69

70
        return SlateDefaultStringComponent;
138✔
71
    }
72

73
    getType(): SlateStringContext['type'] {
74
        const path = AngularEditor.findPath(this.viewContext.editor, this.context.text);
149✔
75
        const parentPath = Path.parent(path);
149✔
76

77
        // COMPAT: Render text inside void nodes with a zero-width space.
78
        // So the node can contain selection but the text is not visible.
79
        if (this.viewContext.editor.isVoid(this.context.parent)) {
149✔
80
            return 'voidString';
1✔
81
        }
82

83
        // COMPAT: If this is the last text node in an empty block, render a zero-
84
        // width space that will convert into a line break when copying and pasting
85
        // to support expected plain text.
86
        if (
148✔
87
            this.context.leaf.text === '' &&
178✔
88
            this.context.parent.children[this.context.parent.children.length - 1] === this.context.text &&
89
            !this.viewContext.editor.isInline(this.context.parent) &&
90
            Editor.string(this.viewContext.editor, parentPath) === ''
91
        ) {
92
            return 'lineBreakEmptyString';
10✔
93
        }
94

95
        // COMPAT: If the text is empty, it's because it's on the edge of an inline
96
        // node, so we render a zero-width space so that the selection can be
97
        // inserted next to it still.
98
        if (this.context.leaf.text === '') {
138!
99
            return 'emptyText';
×
100
        }
101

102
        // COMPAT: Browsers will collapse trailing new lines at the end of blocks,
103
        // so we need to add an extra trailing new lines to prevent that.
104
        if (this.context.isLast && this.context.leaf.text.slice(-1) === '\n') {
138!
105
            return 'compatString';
×
106
        }
107

108
        return 'string';
138✔
109
    }
110

111
    getContext(): SlateStringContext {
112
        const stringType = this.getType();
149✔
113
        return {
149✔
114
            text: this.context.leaf.text,
115
            elementStringLength: Node.string(this.context.parent).length,
116
            type: stringType
117
        };
118
    }
119

120
    memoizedContext(prev: SlateStringContext, next: SlateStringContext): boolean {
121
        return false;
6✔
122
    }
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc