Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ desktop.ini
*.zip
native/**/build
.ccls-cache

.fake
12 changes: 7 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Release/netcoreapp3.0/fvim.dll",
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/FVim.dll",
"args": [],
"cwd": "${workspaceFolder}/bin/Release/netcoreapp3.0/",
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole",
"justMyCode": false
},
"console": "integratedTerminal",
"justMyCode": false,
"enableStepFiltering": false
}

]
}
12 changes: 11 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
"tasks": [
{
"label": "build",
"command": "dotnet build -c Release",
"type": "shell",
"command": "dotnet",
"args": [
"msbuild",
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true",
"/t:build",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
Expand Down
File renamed without changes.
36 changes: 15 additions & 21 deletions Views/Cursor.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ open Avalonia.Media.Imaging
open Avalonia.Skia
open Avalonia.Threading
open Avalonia.VisualTree
open SkiaSharp
open System
open System.Collections.Generic
open System.Reactive.Disposables
Expand All @@ -29,9 +28,10 @@ type Cursor() as this =
static let IsActiveProperty = AvaloniaProperty.Register<Cursor, bool>("IsActive")

let mutable cursor_timer: IDisposable = null
let mutable bgbrush: SolidColorBrush = SolidColorBrush(Colors.Black)
let mutable fgbrush: SolidColorBrush = SolidColorBrush(Colors.White)
let mutable spbrush: SolidColorBrush = SolidColorBrush(Colors.Red)
let mutable fg = Colors.White
let mutable bg = Colors.Black
let mutable sp = Colors.Red

let mutable cursor_fb = AllocateFramebuffer (20.0) (20.0) 1.0
let mutable cursor_fb_vm = CursorViewModel(Some -1)
let mutable cursor_fb_s = 1.0
Expand All @@ -49,9 +49,8 @@ type Cursor() as this =
true
else false

let fgpaint = new SKPaint()
let bgpaint = new SKPaint()
let sppaint = new SKPaint()
let _buffer_glyph = [| 0u |]
let _buffer_glyph_mem = ReadOnlyMemory(_buffer_glyph)

let cursorTimerRun action time =
if cursor_timer <> null then
Expand Down Expand Up @@ -81,12 +80,9 @@ type Cursor() as this =
then ()
else
(* update the settings *)
if this.ViewModel.fg <> fgbrush.Color then
fgbrush <- SolidColorBrush(this.ViewModel.fg)
if this.ViewModel.bg <> bgbrush.Color then
bgbrush <- SolidColorBrush(this.ViewModel.bg)
if this.ViewModel.sp <> spbrush.Color then
spbrush <- SolidColorBrush(this.ViewModel.sp)
fg <- this.ViewModel.fg
bg <- this.ViewModel.bg
sp <- this.ViewModel.sp
(* reconfigure the cursor *)
showCursor true
cursorTimerRun blinkon this.ViewModel.blinkwait
Expand Down Expand Up @@ -142,14 +138,12 @@ type Cursor() as this =

match this.ViewModel.shape, this.ViewModel.cellPercentage with
| CursorShape.Block, _ ->
let _, typeface = GetTypeface(this.ViewModel.text, this.ViewModel.italic, this.ViewModel.bold, this.ViewModel.typeface, this.ViewModel.wtypeface)
SetForegroundBrush(fgpaint, this.ViewModel.fg, typeface, this.ViewModel.fontSize)
bgpaint.Color <- this.ViewModel.bg.ToSKColor()
sppaint.Color <- this.ViewModel.sp.ToSKColor()
let typeface = GetTypeface(this.ViewModel.text, this.ViewModel.italic, this.ViewModel.bold, this.ViewModel.typeface, this.ViewModel.wtypeface)
let bounds = Rect(this.Bounds.Size)
let render_block (ctx: 'a) =
if this.IsActive then
RenderText(ctx, bounds, scale, fgpaint, bgpaint, sppaint, this.ViewModel.underline, this.ViewModel.undercurl, this.ViewModel.text.ToString(), ValueNone)
_buffer_glyph.[0] <- this.ViewModel.text.Codepoint
RenderText(ctx, bounds, scale, fg, bg, sp, this.ViewModel.underline, this.ViewModel.undercurl, Unshaped _buffer_glyph_mem, typeface, this.ViewModel.fontSize)
else
let brush = SolidColorBrush(this.ViewModel.bg)
ctx.DrawRectangle(brush, Pen(brush), RoundedRect(bounds))
Expand All @@ -158,9 +152,9 @@ type Cursor() as this =
match ctx.PlatformImpl with
| :? ISkiaDrawingContextImpl ->
// immediate
SetOpacity fgpaint this.Opacity
SetOpacity bgpaint this.Opacity
SetOpacity sppaint this.Opacity
fg <- UpdateOpacity fg this.Opacity
bg <- UpdateOpacity bg this.Opacity
sp <- UpdateOpacity sp this.Opacity
render_block ctx.PlatformImpl
| _ ->
// deferred
Expand Down
56 changes: 28 additions & 28 deletions Views/Editor.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ open FVim.ui
open FVim.wcwidth

open ReactiveUI
open SkiaSharp
open SkiaSharp.HarfBuzz
open Avalonia
open Avalonia.Controls
open Avalonia.Markup.Xaml
Expand All @@ -29,6 +27,7 @@ module private EditorHelper =

open EditorHelper
open System.Text
open Avalonia.Media

type Editor() as this =
inherit Canvas()
Expand Down Expand Up @@ -80,21 +79,14 @@ type Editor() as this =
let px = pt * grid_scale
Point(Math.Ceiling px.X, Math.Ceiling px.Y) / grid_scale

let mutable fgpaint = null
let mutable bgpaint = null
let mutable sppaint = null
let mutable _render_glyph_buf = [||]
let mutable _render_char_buf = [||]

let drawBuffer (ctx: IDrawingContextImpl) row col colend hlid (issym: bool) =

let font, fontwide, fontsize = grid_vm.GetFontAttrs()
let fg, bg, sp, attrs = theme.GetDrawAttrs hlid
let shaper, typeface = GetTypeface(grid_vm.[row, col].text, attrs.italic, attrs.bold, font, fontwide)

if fgpaint = null then
fgpaint <- new SKPaint()
bgpaint <- new SKPaint()
sppaint <- new SKPaint()
SetForegroundBrush(fgpaint, fg, typeface, fontsize)
let typeface = GetTypeface(grid_vm.[row, col].text, attrs.italic, attrs.bold, font, fontwide)

let nr_col =
match wswidth grid_vm.[row, colend - 1].text with
Expand All @@ -107,24 +99,32 @@ type Editor() as this =
let bottomRight = topLeft + grid_vm.GetPoint 1 nr_col
let bg_region = Rect(topLeft, bottomRight)

bgpaint.Color <- bg.ToSKColor()
sppaint.Color <- sp.ToSKColor()

let txt =
let sb = StringBuilder()
for i = col to colend - 1 do
match grid_vm.[row, i] with
| { text = { c1 = c1; c2 = c2; isSurrogatePair = true } } -> sb.Append(c1).Append(c2) |> ignore
| { text = { c1 = c1 } } -> sb.Append(c1) |> ignore
sb.ToString()

let shaping =
if txt.Length > 1 && txt.Length < 5 && issym && States.font_ligature
then ValueSome shaper
else ValueNone
let txt =
if nr_col > 1 && nr_col < 5 && issym && States.font_ligature then
if _render_char_buf.Length < (colend - col) * 2 then
_render_char_buf <- Array.zeroCreate ((colend - col) * 2)
let mutable _len = 0
for i = col to colend - 1 do
match grid_vm.[row, i].text with
| { c1 = c1; c2 = c2; isSurrogatePair = true } ->
_render_char_buf.[_len] <- c1
_render_char_buf.[_len + 1] <- c2
_len <- _len + 2
| { c1 = c1 } ->
_render_char_buf.[_len] <- c1
_len <- _len + 1

Shaped <| ReadOnlyMemory(_render_char_buf, 0, _len)
else
if _render_glyph_buf.Length < colend - col then
_render_glyph_buf <- Array.zeroCreate (colend - col)
for i = col to colend - 1 do
_render_glyph_buf.[i - col] <- grid_vm.[row, i].text.Codepoint

Unshaped <| ReadOnlyMemory(_render_glyph_buf, 0, colend - col)

try
RenderText(ctx, bg_region, grid_scale, fgpaint, bgpaint, sppaint, attrs.underline, attrs.undercurl, txt, shaping)
RenderText(ctx, bg_region, grid_scale, fg, bg, sp, attrs.underline, attrs.undercurl, txt, typeface, fontsize)
with ex -> trace grid_vm "drawBuffer: %s" (ex.ToString())

// assembles text from grid and draw onto the context.
Expand Down
2 changes: 2 additions & 0 deletions Views/MainWindow.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ open Avalonia.Rendering
open Avalonia.Interactivity
open Avalonia.VisualTree

open Avalonia.Diagnostics

#nowarn "0025"

open System.Runtime.InteropServices
Expand Down
4 changes: 4 additions & 0 deletions def.fs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ type Rune =
}
with
override x.ToString() = if x.isSurrogatePair then sprintf "%c%c" x.c1 x.c2 else x.c1.ToString()
member x.Codepoint with get() =
if x.isSurrogatePair
then 0x10000u + (uint x.c1 - 0xD800u) * 0x400u + (uint x.c2 - 0xDC00u)
else uint x.c1
static member empty = { c1 = ' '; c2 = char 0; isSurrogatePair = false }

[<Struct>]
Expand Down
10 changes: 2 additions & 8 deletions fvim.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,26 @@
<AvaloniaResource Include="**\*.xaml">
<SubType>Designer</SubType>
</AvaloniaResource>
<EmbeddedResource Include="nerd.ttf" />
<EmbeddedResource Include="Fonts\nerd.ttf" />
<Content Include="Assets\*" />
<None Include="icons\*.ico" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.0-preview2" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.0-preview2" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.0-preview2" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.0-preview2" />
<PackageReference Include="Avalonia.Angle.Windows.Natives" Version="2.1.0.2019013001" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.0-preview2" />

<PackageReference Include="FSharp.Control.Reactive" Version="4.4.2" />
<PackageReference Include="FSharp.Data" Version="3.3.3" />
<PackageReference Include="HarfBuzzSharp" Version="2.6.1.7" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.6.1.7" />
<PackageReference Include="MessagePack" Version="1.9.11" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="NSubsys" Version="1.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.80.0" />
<PackageReference Include="TaskBuilder.fs" Version="2.1.0" />
<PackageReference Update="FSharp.Core" Version="4.7.2" />
<PackageReference Include="UACHelper" Version="1.3.0.5" />
Expand Down
4 changes: 2 additions & 2 deletions states.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ let mutable font_subpixel = true
let mutable font_autosnap = true
let mutable font_ligature = true
let mutable font_hintLevel = SKPaintHinting.NoHinting
let mutable font_weight_normal = SKFontStyleWeight.Normal
let mutable font_weight_bold = SKFontStyleWeight.Bold
let mutable font_weight_normal = FontWeight.Normal
let mutable font_weight_bold = FontWeight.Bold
let mutable font_lineheight = LineHeightOption.Default
let mutable font_nonerd = false

Expand Down
Loading