[fix] update errs
This commit is contained in:
parent
d3a89a5b08
commit
d38467183c
5 changed files with 77 additions and 50 deletions
52
src/doci.xqm
52
src/doci.xqm
|
|
@ -66,9 +66,10 @@ declare function doci:text($doci as doci:doci)
|
|||
as xs:string{
|
||||
string-join($doci?lines,$doci?separator)
|
||||
};
|
||||
|
||||
(: number of lines:)
|
||||
declare function doci:lines($doci as doci:doci)
|
||||
as xs:string{
|
||||
as xs:integer{
|
||||
$doci?lines=>count()
|
||||
};
|
||||
|
||||
|
|
@ -82,30 +83,39 @@ switch () {
|
|||
default return $doci:default-separator
|
||||
}
|
||||
};
|
||||
|
||||
(: apply change:)
|
||||
declare function doci:change($doci as doci:doci,$change as doci:TextDocumentContentChangeEvent)
|
||||
declare function doci:update($doci as doci:doci,$change as doci:TextDocumentContentChangeEvent)
|
||||
as doci:doci{
|
||||
let $lines:= doci:split-lines($change?text)
|
||||
return if(empty($change?range))
|
||||
then doci:doci($lines,$doci?separator)
|
||||
else let $range:=$change?range
|
||||
let $sline:=$range?start?line
|
||||
let $eline:=$range?end?line
|
||||
return switch(){
|
||||
case $sline eq $eline and count($lines) eq 1
|
||||
return let $line:=$doci?lines[$sline+1]
|
||||
let $new:=substring($line,1,$range?start?character)
|
||||
|| $lines ||
|
||||
substring($line,1+$range?end?character)
|
||||
let $lines:= doci:split-lines($change?text)
|
||||
return if(empty($change?range))
|
||||
then doci:doci($lines,$doci?separator)
|
||||
else
|
||||
let $range:=$change?range
|
||||
let $sline:= $range?start?line
|
||||
let $eline:= $range?end?line
|
||||
|
||||
let $ulines:=( $doci?lines[position() le $sline],
|
||||
$new,
|
||||
$doci?lines[position() gt 1+$sline]
|
||||
)
|
||||
return doci:doci($ulines, $doci?separator)
|
||||
(: string from start line before insert :)
|
||||
let $head:= substring( $doci?lines[$sline+1] ,1, $range?start?character )
|
||||
(: string from edit end to end of line :)
|
||||
let $head:= substring( $doci?lines[$sline+1] ,1, $range?start?character )
|
||||
let $last := substring( $doci?lines[$eline+1] , $range?end?character +1)
|
||||
|
||||
default return error(#doci:change,"oh")
|
||||
}
|
||||
let $ulines := (
|
||||
subsequence($doci?lines, 1, $sline) (: lines before edit :)
|
||||
,
|
||||
if($sline eq $eline)
|
||||
then ($head || $lines[1] || $last)
|
||||
|
||||
else (
|
||||
$head || $lines[1],
|
||||
subsequence( $lines,2, count( $lines - 2)),
|
||||
$lines[last()] ||$last
|
||||
),
|
||||
|
||||
subsequence($doci?lines, $eline+2) (: lines after edit :)
|
||||
)
|
||||
return doci:doci($ulines,$doci?separator)
|
||||
};
|
||||
|
||||
declare function doci:split-lines($text as xs:string)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue