mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-19 14:17:40 +00:00
fix(developer): trim new words entered into the wordlist editor
Fixes: #12668
This commit is contained in:
parent
d65ee54a90
commit
862c5cefa1
2 changed files with 113 additions and 90 deletions
|
|
@ -1,87 +1,88 @@
|
|||
inherited frameWordlistEditor: TframeWordlistEditor
|
||||
BorderIcons = []
|
||||
BorderStyle = bsNone
|
||||
Caption = 'frameWordlistEditor'
|
||||
ClientHeight = 338
|
||||
ClientWidth = 651
|
||||
OnResize = FormResize
|
||||
ExplicitWidth = 651
|
||||
ExplicitHeight = 338
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object pages: TPageControl
|
||||
Left = 0
|
||||
Top = 0
|
||||
Width = 651
|
||||
Height = 338
|
||||
ActivePage = pageDesign
|
||||
Align = alClient
|
||||
TabOrder = 0
|
||||
TabPosition = tpBottom
|
||||
OnChanging = pagesChanging
|
||||
ExplicitWidth = 635
|
||||
ExplicitHeight = 299
|
||||
object pageDesign: TTabSheet
|
||||
Caption = 'Design'
|
||||
ImageIndex = -1
|
||||
ExplicitLeft = 0
|
||||
ExplicitTop = 0
|
||||
ExplicitWidth = 627
|
||||
ExplicitHeight = 273
|
||||
object gridWordlist: TStringGridEditControlled
|
||||
Left = 0
|
||||
Top = 0
|
||||
Width = 643
|
||||
Height = 271
|
||||
Align = alClient
|
||||
ColCount = 3
|
||||
DefaultRowHeight = 16
|
||||
DefaultDrawing = False
|
||||
FixedCols = 0
|
||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing, goEditing, goTabs, goAlwaysShowEditor]
|
||||
TabOrder = 0
|
||||
OnClick = gridWordlistClick
|
||||
OnDrawCell = gridWordlistDrawCell
|
||||
OnSetEditText = gridWordlistSetEditText
|
||||
ExplicitWidth = 627
|
||||
ExplicitHeight = 232
|
||||
end
|
||||
object panGridControls: TPanel
|
||||
Left = 0
|
||||
Top = 271
|
||||
Width = 643
|
||||
Height = 41
|
||||
Align = alBottom
|
||||
TabOrder = 1
|
||||
ExplicitTop = 232
|
||||
ExplicitWidth = 627
|
||||
object cmdDeleteRow: TButton
|
||||
Left = 0
|
||||
Top = 6
|
||||
Width = 75
|
||||
Height = 25
|
||||
Caption = '&Delete row'
|
||||
TabOrder = 0
|
||||
OnClick = cmdDeleteRowClick
|
||||
end
|
||||
object cmdSortByFrequency: TButton
|
||||
Left = 81
|
||||
Top = 6
|
||||
Width = 104
|
||||
Height = 25
|
||||
Caption = '&Sort by frequency'
|
||||
TabOrder = 1
|
||||
OnClick = cmdSortByFrequencyClick
|
||||
end
|
||||
end
|
||||
end
|
||||
object pageCode: TTabSheet
|
||||
Caption = 'Code'
|
||||
ImageIndex = -1
|
||||
ExplicitLeft = 0
|
||||
ExplicitTop = 0
|
||||
ExplicitWidth = 0
|
||||
ExplicitHeight = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
inherited frameWordlistEditor: TframeWordlistEditor
|
||||
BorderIcons = []
|
||||
BorderStyle = bsNone
|
||||
Caption = 'frameWordlistEditor'
|
||||
ClientHeight = 338
|
||||
ClientWidth = 651
|
||||
OnResize = FormResize
|
||||
ExplicitWidth = 651
|
||||
ExplicitHeight = 338
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object pages: TPageControl
|
||||
Left = 0
|
||||
Top = 0
|
||||
Width = 651
|
||||
Height = 338
|
||||
ActivePage = pageDesign
|
||||
Align = alClient
|
||||
TabOrder = 0
|
||||
TabPosition = tpBottom
|
||||
OnChanging = pagesChanging
|
||||
ExplicitWidth = 635
|
||||
ExplicitHeight = 299
|
||||
object pageDesign: TTabSheet
|
||||
Caption = 'Design'
|
||||
ImageIndex = -1
|
||||
ExplicitLeft = 0
|
||||
ExplicitTop = 0
|
||||
ExplicitWidth = 627
|
||||
ExplicitHeight = 273
|
||||
object gridWordlist: TStringGridEditControlled
|
||||
Left = 0
|
||||
Top = 0
|
||||
Width = 643
|
||||
Height = 271
|
||||
Align = alClient
|
||||
ColCount = 3
|
||||
DefaultRowHeight = 16
|
||||
DefaultDrawing = False
|
||||
FixedCols = 0
|
||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing, goEditing, goTabs, goAlwaysShowEditor]
|
||||
TabOrder = 0
|
||||
OnClick = gridWordlistClick
|
||||
OnDrawCell = gridWordlistDrawCell
|
||||
OnSelectCell = gridWordlistSelectCell
|
||||
OnSetEditText = gridWordlistSetEditText
|
||||
ExplicitWidth = 627
|
||||
ExplicitHeight = 232
|
||||
end
|
||||
object panGridControls: TPanel
|
||||
Left = 0
|
||||
Top = 271
|
||||
Width = 643
|
||||
Height = 41
|
||||
Align = alBottom
|
||||
TabOrder = 1
|
||||
ExplicitTop = 232
|
||||
ExplicitWidth = 627
|
||||
object cmdDeleteRow: TButton
|
||||
Left = 0
|
||||
Top = 6
|
||||
Width = 75
|
||||
Height = 25
|
||||
Caption = '&Delete row'
|
||||
TabOrder = 0
|
||||
OnClick = cmdDeleteRowClick
|
||||
end
|
||||
object cmdSortByFrequency: TButton
|
||||
Left = 81
|
||||
Top = 6
|
||||
Width = 104
|
||||
Height = 25
|
||||
Caption = '&Sort by frequency'
|
||||
TabOrder = 1
|
||||
OnClick = cmdSortByFrequencyClick
|
||||
end
|
||||
end
|
||||
end
|
||||
object pageCode: TTabSheet
|
||||
Caption = 'Code'
|
||||
ImageIndex = -1
|
||||
ExplicitLeft = 0
|
||||
ExplicitTop = 0
|
||||
ExplicitWidth = 0
|
||||
ExplicitHeight = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ type
|
|||
procedure cmdDeleteRowClick(Sender: TObject);
|
||||
procedure gridWordlistClick(Sender: TObject);
|
||||
procedure cmdSortByFrequencyClick(Sender: TObject);
|
||||
procedure gridWordlistSelectCell(Sender: TObject; ACol, ARow: Integer;
|
||||
var CanSelect: Boolean);
|
||||
private
|
||||
FWordlist: TWordlistTsvFile;
|
||||
frameSource: TframeTextEditor;
|
||||
|
|
@ -313,6 +315,25 @@ begin
|
|||
ARect.Top+((ARect.Height - gridWordlist.Canvas.TextHeight(LText)) div 2), LText);
|
||||
end;
|
||||
|
||||
procedure TframeWordlistEditor.gridWordlistSelectCell(Sender: TObject; ACol,
|
||||
ARow: Integer; var CanSelect: Boolean);
|
||||
var
|
||||
Value: string;
|
||||
begin
|
||||
if gridWordlist.Col = 0 then
|
||||
begin
|
||||
// The value is trimmed in the backing data but trim it here also when
|
||||
// we exit a cell, so the visible text matches
|
||||
Value := Trim(gridWordlist.Cells[gridWordlist.Col, gridWordlist.Row]);
|
||||
gridWordlist.Cells[gridWordlist.Col, gridWordlist.Row] := Value;
|
||||
if (gridWordlist.Row = gridWordlist.RowCount - 1) and (Value = '') then
|
||||
begin
|
||||
// And if the last row was just whitespace, show the hint text again
|
||||
FillGridNewRow;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TframeWordlistEditor.gridWordlistSetEditText(Sender: TObject; ACol,
|
||||
ARow: Integer; const Value: string);
|
||||
var
|
||||
|
|
@ -324,12 +345,14 @@ begin
|
|||
|
||||
Inc(FSetup);
|
||||
try
|
||||
TrimmedValue := Value.Trim;
|
||||
|
||||
if ARow = gridWordlist.RowCount - 1 then
|
||||
begin
|
||||
if (Value = '') or (Value = S_AddRowText) then
|
||||
if (TrimmedValue = '') or (TrimmedValue = S_AddRowText) then
|
||||
Exit;
|
||||
|
||||
w.Word := Value;
|
||||
w.Word := TrimmedValue;
|
||||
w.Frequency := 0;
|
||||
w.Comment := '';
|
||||
FWordlist.AddWord(w);
|
||||
|
|
@ -338,7 +361,6 @@ begin
|
|||
end
|
||||
else
|
||||
begin
|
||||
TrimmedValue := Value.Trim;
|
||||
Frequency := StrToIntDef(TrimmedValue.Replace(',', '', [rfReplaceAll]), 0);
|
||||
w := FWordlist.Word[ARow-1];
|
||||
case ACol of
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue