Jump to content


Photo

Selectable text


  • Please log in to reply
1 reply to this topic

#1 Igor Savkic

Igor Savkic
  • Members
  • 185 posts

Posted 15 December 2015 - 11:02 AM

By default all text in SMS application isn't selectable (aside from edit and memo controls) nor it works when contentEditable atribute is set.

Can someone advise on how to fix it and have it working? Yes I know that SMS intended target is mobile platform where that doesn't work but I do work for regular browsers (desktop) and I need this feature.



#2 Nico Wouterse

Nico Wouterse
  • Moderators
  • 250 posts
  • LocationAustralia

Posted 17 December 2015 - 03:48 AM

1) The standard css files lists 'user-select:none' as default for all html-elements, with an override for memo and editbox which get the vale 'auto'

2) See this post (https://jonlennartaa...n-smart-pascal/) which explains the use of the 'contenteditable' attribute

 

Best I can come up with is a combination of the two (user-select and contenteditable).

Works for all types of html elements in Chrome and FF, didn't check Safari, does not work in Edge

unit Form1;
 
interface
 
uses
  SmartCL.System, SmartCL.Graphics, SmartCL.Components, SmartCL.Forms,
  SmartCL.Fonts, SmartCL.Borders, SmartCL.Application, SmartCL.Controls.Label,
  SmartCL.Controls.EditBox;
 
type
  TMyLabel = class(TW3Label)
  protected
    procedure StyleTagObject; override;
  end;
 
  TForm1 = class(TW3Form)
  private
    {$I 'Form1:intf'}
  protected
    procedure InitializeForm; override;
    procedure InitializeObject; override;
    procedure FormActivated; override;
    procedure Resize; override;
    MyLabel1 : TMyLabel;
  end;
 
implementation
 
{ TForm1 }
 
procedure TMyLabel.StyleTagObject;
Begin
  inherited;
//  w3_setAttrib(handle,'type','text');
//  w3_setAttrib(handle,'contenteditable',True);
//  w3_setStyle(handle,'user-select','auto');
  w3_setStyle(handle,'-webkit-user-select','auto');
end;
 
procedure TForm1.InitializeForm;
begin
  inherited;
  // this is a good place to initialize components
  MyLabel1 := TMyLabel.Create(self);
  MyLabel1.InnerHTML := 'ddddd';
  MyLabel1.OnClick := procedure(Sender: TObject)
  begin
   asm
    function selectElementContents(el) {
      var range = document.createRange();
      range.selectNodeContents(el);
      var sel = window.getSelection();
      sel.removeAllRanges();
      sel.addRange(range);
    }
 
    var el = document.getElementById("OBJ4");    // <=== demo
    selectElementContents(el);
   end;
  end;
end;
 
procedure TForm1.InitializeObject;
begin
  inherited;
  {$I 'Form1:impl'}
end;
 
procedure TForm1.FormActivated;
begin
  inherited;
  ReSize;
end;
 
procedure TForm1.Resize;
begin
  inherited;
  If assigned(MyLabel1) then
    MyLabel1.SetBounds(20,20,100,30);
end;
 
initialization
  Forms.RegisterForm({$I %FILE%}, TForm1);
end.

Nico Wouterse




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users