?
Solved

Automatic counter-tags in HTML Editor

Posted on 2003-03-01
9
Medium Priority
?
273 Views
Last Modified: 2013-12-16
Ok, I've knocked together an MDI Raw HTML editor with a 'preview' tab to help the user see their page taking shape without cluttering up the taskbar with browser windows. TabControl at the bottom to make navigation easy, and a SynEdit + HTML highlighter to make it easy reading. It's all working nice and spiffy, but the one last feature I want in there, I'm having trouble with.

I'd like it to be able to automatically add a counter tag when you type a normal tag in. e.g.

You type <table> and it adds </table> to the line.

Thanks for your time,
Marajin/Tom
0
Comment
Question by:marajin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Expert Comment

by:ILE
ID: 8049946
If i andwrstand u corrrectly you wont to auto add counter tag when u finished tyoed a tag

becouse i did the all coding in the memo coponent
100 % working solution


procedure TForm1.Memo1Change(Sender: TObject);
var s:string;
   t1,t2:integer;
begin
s:=memo1.lines[memo1.caretpos.y];
t2:=Memo1.CaretPos.X;
if (t2>0) and (s[t2]='>') then
   begin
     for t1:=t2 downto 0 do
     if (s[t1]='<') then
     begin
       if s[t1+1]='\' then break;
       label1.caption:=copy(s,t1,t2-t1+1);
        if pos('<\'+copy(s,t1+1,t2-t1),s)=0 then memo1.lines[memo1.CaretPos.Y]:=s+'<\'+copy(s,t1+1,t2-t1);
       break;
     end;
   end;
end;


writen in delphi 7
in earlier versions of delphi meybe is memo1.caretpos.line and memo1.caretpos.col   instead of memo1.caretpos.x and .....y


easy arent :))??
0
 

Author Comment

by:marajin
ID: 8050200
It seems to half work, That is, it grabs the next line of text and puts the counter tag in....after I do some messing about.

See it's a SynEdit component (http://synedit.sourceforge.net) not a normal memo...

changing the code to this:

procedure TMDIChild.SynEdit1Change(Sender: TObject);
var
   s:string;
   t1,t2:integer;
   Y:integer;
begin
Y:=SynEdit1.CaretY;
s:=SynEdit1.lines[Y];
t2:=SynEdit1.Caretx;
if (t2>0) and (s[t2]='>') then
  begin
    for t1:=t2 downto 0 do
    if (s[t1]='<') then
    begin
      if s[t1+1]='/' then break;
      label1.caption:=copy(s,t1,t2-t1+1);
      Y:=SynEdit1.CaretY;
       if pos('</'+copy(s,t1+1,t2-t1),s)=0 then SynEdit1.lines[Y-1]:=(s+'</'+copy(s,t1+1,t2-t1));
      break;
    end;
  end;
end;

Gets me nearly there, only it grabs the NEXT line of text, and makes the counter tag.... If I use a Y-1 for the initial value too, which _should_ fix this, nothing happens at all.

This is also Delphi 6
0
 
LVL 3

Expert Comment

by:ILE
ID: 8051513
i dont realy anderstand what u meen with NEXT line of text

meybe i dont andersand HTML :))

put me a example what u wont



0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 

Author Comment

by:marajin
ID: 8051597
Say you have this in the SynEdit:

<html>

<body>

</body>

</html>

You type in <tag> between the <html> and <body> so you get:

<html>
<tag>
<body>

</body>

</html>

The code sees that tag and the result is:

<html>
<body></body>
<body>

</body>

</html>

so it is using the next line down (<body>) instead of <Tag> which the user typed in
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8054807
s:=SynEdit1.lines[Y-1];
0
 

Author Comment

by:marajin
ID: 8055414
"s:=SynEdit1.lines[Y-1]; "

Doesn't work. Nothing at all happens
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8077483
I don't have that component, but in a TMemo, I would use the OnKeyDown Event, so I could monitor all of the key input,, , , , here's my sugestion



  private
    { Private declarations }
    Str1: String;
    Trap: Boolean;



procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var
SelPos: Integer;
begin
inherited;
if Key = ' ' then Trap := False;
if Key = '>' then
  begin
  Str1 := Str1+'>';
  Trap := False;
  Label2.Caption := Str1;
  SelPos := memo1.SelStart;
  Memo1.SelText := Str1;
  memo1.SelStart := SelPos;
  end;

if Trap then
Str1 := Str1+Key;

if Key = '<' then
  begin
  Trap := True;
  Str1 := '<\';
  end;

end;
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 400 total points
ID: 8077528
whoops, I forgot to check and see if they left the tag to type somewhere else - -


  private
    { Private declarations }
    Str1: String;
    Trap: Boolean;
    LastPos: Integer;


procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var
SelPos: Integer;
begin
inherited;
if Key = ' ' then Trap := False;
if Key = '>' then
  begin
  if Length(Str1) < 3 then Exit;
  Str1 := Str1+'>';
  Trap := False;
  Label2.Caption := Str1;
  SelPos := memo1.SelStart;
  Memo1.SelText := Str1;
  memo1.SelStart := SelPos;
  end;

if Trap then
  begin
  SelPos := memo1.SelStart;
  if SelPos - LastPos <> 1 then
    begin
    Trap := False;
    Str1 := '';
    end;
  LastPos := SelPos;
  Str1 := Str1+Key;
  end;

if Key = '<' then
  begin
  Trap := True;
  Str1 := '<\';
  LastPos := memo1.SelStart;
  end;

end;
0
 

Author Comment

by:marajin
ID: 8137588
Thanks for that, yeah it seems to work just fine now.
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question